pub trait Subscription {
// Required methods
fn unsubscribe(self);
fn is_closed(&self) -> bool;
// Provided method
fn unsubscribe_when_dropped(self) -> SubscriptionGuard<Self>
where Self: Sized { ... }
}Expand description
Subscription trait for managing observable subscriptions
Provides methods to cancel a subscription and check its status.
Uses move semantics for unsubscribe to match the terminal nature of the
operation, consistent with Observer’s error(self) and complete(self)
methods.
Required Methods§
Sourcefn unsubscribe(self)
fn unsubscribe(self)
Cancel the subscription (terminal operation, consumes self)
Provided Methods§
Sourcefn unsubscribe_when_dropped(self) -> SubscriptionGuard<Self>where
Self: Sized,
fn unsubscribe_when_dropped(self) -> SubscriptionGuard<Self>where
Self: Sized,
Activates “RAII” behavior for this subscription. That means
unsubscribe() will be called automatically as soon as the returned
value goes out of scope.
Attention: If you don’t assign the return value to a variable,
unsubscribe() is called immediately, which is probably not what you
want!
Implementations on Foreign Types§
Source§impl Subscription for ()
Unit subscription - always closed, does nothing
impl Subscription for ()
Unit subscription - always closed, does nothing
Source§impl<P: Subscription> Subscription for Option<P>
Option subscription - None is closed, Some delegates to inner
impl<P: Subscription> Subscription for Option<P>
Option subscription - None is closed, Some delegates to inner