Struct wnf::Subscription

source ·
pub struct Subscription<'a, F> { /* private fields */ }
Available on crate feature subscribe only.
Expand description

A subscription of a listener to updates of a state

This is returned from OwnedState::subscribe and BorrowedState::subscribe.

Note that the listener is automatically unsubscribed when the Subscription<'_, F> is dropped. In this case, errors while unsubscribing are silently ignored. If you want to handle them explicitly, use the Subscription::unsubscribe method, which returns an io::Result<()>. Note that the listener will not be called anymore after unsubscribing, even when there is an error.

If you want to keep the subscription for as long as the process is running and the state exists, use the Subscription::forget method.

Implementations§

Forgets this Subscription<'_, F>, effectively keeping it forever

When a Subscription<'_, F> is dropped, the listener is unsubscribed. You can avoid this behavior by calling this method. It consumes the Subscription<'_, F> without dropping it, effectively keeping the subscription for as long as the process is running and the state exists.

Unsubscribes the listener for this Subscription<'_, F>

This happens automatically when the Subscription<'_, F> is dropped (unless you call Subscription::forget), so there is usually no need to call this method. Its only purpose is to enable you to handle errors while unsubscribing. Note that the listener will not be called anymore after unsubscribing, even when there is an error.

Errors

Returns an error if unsubscribing fails

Trait Implementations§

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more