pub struct SubscriberState { /* private fields */ }Expand description
Stores the possible states a subscriber can be in. Useful to track the state of an unknown upstream source of signals based only on those signals.
Debug asserts ensure that no invalid state changes happen, like changing a completed state into an errored one, or trying to call unsubscribe twice.
By default it’s in the “waiting” state.
Implementations§
Source§impl SubscriberState
impl SubscriberState
Sourcepub fn is_waiting(&self) -> bool
pub fn is_waiting(&self) -> bool
Is considered “waiting” when nothing had happened yet.
This flag starts as true and cannot be set. Once false, stays
false.
Sourcepub fn is_primed(&self) -> bool
pub fn is_primed(&self) -> bool
Is considered “primed” when it had seen at least one next call.
This flag cannot be unset, once true, stays true.
Sourcepub fn is_completed(&self) -> bool
pub fn is_completed(&self) -> bool
Is considered “completed” once it is marked as completed.
After which, only unsubscribe can be called, everything else will
panic in debug builds.
This flag cannot be unset, once true, stays true.
Sourcepub fn is_completed_but_not_primed(&self) -> bool
pub fn is_completed_but_not_primed(&self) -> bool
True when the state was completed without ever seeing a single next!
Sourcepub fn is_errored(&self) -> bool
pub fn is_errored(&self) -> bool
Is “errored” once it is marked as errored.
After which, only unsubscribe can be called, everything else will
panic in debug builds.
This flag cannot be unset, once true, stays true.
Sourcepub fn is_unsubscribed(&self) -> bool
pub fn is_unsubscribed(&self) -> bool
Is “unsubscribed” once it is marked as unsubscribed.
After which, only unsubscribe can be called, everything else will
panic in debug builds.
This flag cannot be unset, once true, stays true.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
It’s considered “closed” once it’s either unsubscribed, or finished, meaning it either completed or errored.
This flag cannot be unset, once true, stays true.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
It’s considered “finished” once it’s either completed or errored.
This flag cannot be unset, once true, stays true.
Sourcepub fn is_closed_but_primed(&self) -> bool
pub fn is_closed_but_primed(&self) -> bool
True when closed, but also primed! Useful to see if something has useful value, and will definitely not get a new one.
Sourcepub fn is_closed_but_not_primed(&self) -> bool
pub fn is_closed_but_not_primed(&self) -> bool
True if it’s closed but hadn’t received a next call. Useful to see if something never had a useful value, and will definitely not have one.
pub fn is_closed_but_not_primed_and_not_completed(&self) -> bool
pub fn is_closed_but_not_completed(&self) -> bool
pub fn is_closed_but_not_errored(&self) -> bool
pub fn is_closed_but_not_completed_and_primed(&self) -> bool
Sourcepub fn next(&mut self)
pub fn next(&mut self)
Marks it as no longer waiting, and primed.
It will panic in debug builds when called from an already closed state.
Sourcepub fn complete(&mut self)
pub fn complete(&mut self)
Marks it as completed and no longer waiting.
It will panic in debug builds when called from an already closed state.
Sourcepub fn error(&mut self)
pub fn error(&mut self)
Marks it as errored and no longer waiting.
It will panic in debug builds when called from an already closed state.
Sourcepub fn unsubscribe(&mut self)
pub fn unsubscribe(&mut self)
Marks it as unsubscribed and no longer waiting.
It will panic in debug builds when called from an already unsubscribed state.
Sourcepub fn unsubscribe_if_not_already(&mut self)
pub fn unsubscribe_if_not_already(&mut self)
Marks it as unsubscribed and no longer waiting.
Does the same thing as unsubscribe but it will never panic even if it
was already marked as unsubscribed.
Unlike with complete/error, which should definitely never happen twice, sometimes the steps to unsubscribe has to be performed differently, when erroring/completing, which may or may not happen before doing an unsubscribe.
Therefore this method is more like a “make sure it’s closed” kind of
method, but one should always prefer using unsubscribe here on
SubscriberState, to catch double unsubscribes.
Sourcepub fn update_with_notification<In, InError>(
&mut self,
notification: &SubscriberNotification<In, InError>,
)
pub fn update_with_notification<In, InError>( &mut self, notification: &SubscriberNotification<In, InError>, )
Applies this notification to the state.
It will panic in debug builds when an invalid state change is attempted.
Sourcepub fn notification_matches_state<In, InError>(
&mut self,
notification: &SubscriberNotification<In, InError>,
) -> bool
pub fn notification_matches_state<In, InError>( &mut self, notification: &SubscriberNotification<In, InError>, ) -> bool
Try to avoid using this function! It’s an escape hatch, and a tool to help narrow down problems.
If using this check before updating the state is what makes your logic work, it means you’re double updating with the same notification. Or upstream is incorrect by sending the same signal multiple times, in which case the problem is not you.
Rest assured these invalid update panics only happen in debug builds!
Sourcepub fn update_with_notification_would_be_invalid<In, InError>(
&self,
notification: &SubscriberNotification<In, InError>,
) -> bool
pub fn update_with_notification_would_be_invalid<In, InError>( &self, notification: &SubscriberNotification<In, InError>, ) -> bool
Try to avoid using this function! It’s an escape hatch, and a tool to help narrow down problems.
If you haven’t yet, try using notification_matches_state as your
safety check before reaching for this function, that one can reveal a
narrower problem.
If using this check before updating the state is what makes your logic work, it means you’re either double updating with the same notification, or you apply a notification that is not a correct state change.
True for all sources of signals: Zero or more Next notifications come first, after which up to 1 Error or Complete signal, and then finally an Unsubscribe signal, and then nothing else.
Or upstream is incorrect by sending the same signal multiple times, in which case the problem is not you.
Rest assured these invalid update panics only happen in debug builds!
Trait Implementations§
Source§impl Clone for SubscriberState
impl Clone for SubscriberState
Source§fn clone(&self) -> SubscriberState
fn clone(&self) -> SubscriberState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SubscriberState
impl Debug for SubscriberState
Source§impl Default for SubscriberState
impl Default for SubscriberState
Source§fn default() -> SubscriberState
fn default() -> SubscriberState
Source§impl Ord for SubscriberState
impl Ord for SubscriberState
Source§fn cmp(&self, other: &SubscriberState) -> Ordering
fn cmp(&self, other: &SubscriberState) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for SubscriberState
impl PartialEq for SubscriberState
Source§impl PartialOrd for SubscriberState
impl PartialOrd for SubscriberState
impl Copy for SubscriberState
impl Eq for SubscriberState
impl StructuralPartialEq for SubscriberState
Auto Trait Implementations§
impl Freeze for SubscriberState
impl RefUnwindSafe for SubscriberState
impl Send for SubscriberState
impl Sync for SubscriberState
impl Unpin for SubscriberState
impl UnwindSafe for SubscriberState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more