Skip to main content

SubscriberState

Struct SubscriberState 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn is_completed_but_not_primed(&self) -> bool

True when the state was completed without ever seeing a single next!

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_closed_but_not_primed_and_not_completed(&self) -> bool

Source

pub fn is_closed_but_not_completed(&self) -> bool

Source

pub fn is_closed_but_not_errored(&self) -> bool

Source

pub fn is_closed_but_not_completed_and_primed(&self) -> bool

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn update_with_notification<In, InError>( &mut self, notification: &SubscriberNotification<In, InError>, )
where In: Signal, InError: Signal,

Applies this notification to the state.

It will panic in debug builds when an invalid state change is attempted.

Source

pub fn notification_matches_state<In, InError>( &mut self, notification: &SubscriberNotification<In, InError>, ) -> bool
where In: Signal, InError: Signal,

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!

Source

pub fn update_with_notification_would_be_invalid<In, InError>( &self, notification: &SubscriberNotification<In, InError>, ) -> bool
where In: Signal, InError: Signal,

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

Source§

fn clone(&self) -> SubscriberState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubscriberState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for SubscriberState

Source§

fn default() -> SubscriberState

Returns the “default value” for a type. Read more
Source§

impl Ord for SubscriberState

Source§

fn cmp(&self, other: &SubscriberState) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SubscriberState

Source§

fn eq(&self, other: &SubscriberState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SubscriberState

Source§

fn partial_cmp(&self, other: &SubscriberState) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for SubscriberState

Source§

impl Eq for SubscriberState

Source§

impl StructuralPartialEq for SubscriberState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Signal for T
where T: 'static + Send + Sync,