pub struct Subscription { /* private fields */ }
Expand description
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§
Source§impl Subscription
impl Subscription
Sourcepub fn unsubscribe(&self)
pub fn unsubscribe(&self)
Stops listening to the stream.
Trait Implementations§
Source§impl Clone for Subscription
impl Clone for Subscription
Source§fn clone(&self) -> Subscription
fn clone(&self) -> Subscription
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for Subscription
impl RefUnwindSafe for Subscription
impl Send for Subscription
impl Sync for Subscription
impl Unpin for Subscription
impl UnwindSafe for Subscription
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
Mutably borrows from an owned value. Read more