[][src]Struct froop::Subscription

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. Froop reference counts the number of children alive to determine when to unsubscribe.

Example:

use froop::{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 froop::{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

Methods

impl Subscription[src]

pub fn unsubscribe(&self)[src]

Stops listening to the stream.

Trait Implementations

impl Clone for Subscription[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> From for T[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.