Struct xi::Subscription[][src]

pub struct Subscription { /* fields omitted */ }

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]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.