Struct xi::Subscription [−][src]
A subscription is a receipt for adding a listener to a stream. Can be used to stop listening.
Subscription lifetimes
Every combinator subscribes to events from its parent stream. It is basically the
same as calling .subscribe()
but with an important twist. Xi reference counts
the number of children alive to determine when to unsubscribe.
Example:
use xi::{Sink, Stream}; let sink: Sink<u32> = Stream::sink(); let stream = sink.stream(); // map is subscribed (once) to stream let map = stream.map(|v| v * 2); let map2 = map.clone(); drop(map); drop(map2); // map is unsubscribed from stream
This is different to regular subscriptions where we must explicitly call .unsubscribe()
on the returned subscription instance.
Example:
use xi::{Sink, Stream}; let sink: Sink<u32> = Stream::sink(); let stream = sink.stream(); // subscribed to stream let sub = stream.subscribe(|v| if let Some(v) = v { println!("{}", v) }); drop(sub); // still subscribed to stream
Implementations
impl Subscription
[src]
pub fn unsubscribe(&self)
[src]
Stops listening to the stream.
Trait Implementations
impl Clone for Subscription
[src]
fn clone(&self) -> Subscription
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for Subscription
impl Send for Subscription
impl Sync for Subscription
impl Unpin for Subscription
impl UnwindSafe for Subscription
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,