Enum calloop::sources::transient::TransientSourceState
source · enum TransientSourceState<T> {
Keep(T),
Register(T),
Disable(T),
Remove(T),
Replace {
new: T,
old: T,
},
None,
}
Expand description
This is the internal state of the TransientSource
, as a separate type so
it’s not exposed.
Variants§
Keep(T)
The source should be kept in the loop.
Register(T)
The source needs to be registered with the loop.
Disable(T)
The source needs to be disabled but kept.
Remove(T)
The source needs to be removed from the loop.
Replace
The source is being replaced by another. For most API purposes (eg.
map()
), this will be treated as the Register
state enclosing the new
source.
Fields
new: T
The new source, which will be registered and used from now on.
old: T
The old source, which will be unregistered and dropped.
None
The source has been removed from the loop and dropped (this might also be observed if there is a panic while changing states).
Implementations§
source§impl<T> TransientSourceState<T>
impl<T> TransientSourceState<T>
sourcefn replace_state<F>(&mut self, replacer: F)where
F: FnOnce(T) -> Self,
fn replace_state<F>(&mut self, replacer: F)where
F: FnOnce(T) -> Self,
If a caller needs to flag the contained source for removal or
registration, we need to replace the enum variant safely. This requires
having a None
value in there temporarily while we do the swap.
If the variant is None
the value will not change and replacer
will
not be called. If the variant is Replace
then replacer
will be
called on the new source, which may cause the old source to leak
registration in the event loop if it has not yet been unregistered.
The replacer
function here is expected to be one of the enum variant
constructors eg. replace(TransientSource::Remove)
.