rust_observable

Crates.iorust_observable
lib.rsrust_observable
version0.2.1
sourcesrc
created_at2023-08-04 21:27:26.155918
updated_at2023-08-05 13:15:47.904417
descriptionPush-based data source Observable type
homepage
repositoryhttps://github.com/hydroper/rust_observable
max_upload_size
id935649
size17,875
Matheus Dias de Souza (hydroper)

documentation

README

Observable

Provides an Observable type used to model push-based data sources. It always uses atomic references, allowing it to be passed to other threads. It is based on a TC39 proposal.

The observer! macro constructs an opaque Observer. You can also implement your own observer type if desired.

Requirements:

  • The Rust standard library (std).
  • Nightly channel.
use rust_observable::*;

fn my_observable() -> Observable<String> {
    Observable::new(|observer| {
        // send initial data
        observer.next("initial value".into());

        // return a cleanup function that runs on unsubscribe.
        || {
            println!("cleanup on unsubscribe");
        }
    })
}

let _ = my_observable()
    .subscribe(observer! {
        next: |value| {},
        error: |error| {},
        complete: || {},
        start: |subscription| {},
    })
    .unsubscribe();

// you can also use functional methods such as `filter` and `map`.
let _ = my_observable()
    .filter(|value| true)
    .map(|value| value);
Commit count: 11

cargo fmt