rxrs 0.1.0-alpha2

Reactive Extensions for Rust
docs.rs failed to build rxrs-0.1.0-alpha2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: rxrs-0.2.0-beta3

🌱 This project is currently at its early stage... most of the features are experimental!

🦀 Contributions Are Welcome!

Example

Basics

(Rust Nightly 1.25+)

#[test]
fn timer()
{
    println!("cur thread {:?}", thread::current().id());

    rx::timer(0, Some(10), NewThreadScheduler::get())
        .skip(3)
        .filter(|i| i % 2 == 0)
        .take(3)
        .map(|v| format!("-{}-", v))
        .observe_on(NewThreadScheduler::get())
        .subf(
            |v| println!("{} on {:?}", v, thread::current().id()),
            (),
            | | println!("complete on {:?}", thread::current().id())
        );

    thread::sleep(::std::time::Duration::from_millis(2000));
}

Output:

cur thread ThreadId(1)
-4- on ThreadId(2)
-6- on ThreadId(2)
-8- on ThreadId(2)
complete on ThreadId(2)

Play with gtk-rs

//(lib for this demo is also a WIP)

let slider = Scale::new_with_range(Orientation::Horizontal, 0.0, 100.0, 1.0);

// create an `Observable` from the slider's `value_changed` event
event!(slider.connect_value_changed, it => it.get_value())
    .start_with(0.0) // events (signals) don't emit an initial value, so we give it one
    .debounce(250, GtkScheduler::get()) // debounce with 250ms to limit input frequency
    .observe_on(NewThreadScheduler::get()) // change to a worker thread
    .map(|v| format!("*{}*", v*v)) // do hard (or blocking) jobs on that thread
    .observe_on(GtkScheduler::get()) // schedule results back to main thread ...
    .subf( // ... for displaying
        byclone!(btn => move |v:String| btn.set_label(&v) )
    );

File Structure

src
├── behaviour_subject.rs
├── connectable_observable.rs
├── fac
│   ├── create.rs
│   ├── mod.rs
│   └── timer.rs
├── lib.rs
├── observable.rs
├── op
│   ├── concat.rs
│   ├── debounce.rs
│   ├── filter.rs
│   ├── map.rs
│   ├── mod.rs
│   ├── multicast.rs
│   ├── observe_on.rs
│   ├── publish.rs
│   ├── skip.rs
│   ├── sub_on.rs
│   ├── take.rs
│   ├── take_until.rs
│   └── tap.rs
├── scheduler.rs
├── subject.rs
├── subscriber.rs
├── unsub_ref.rs
└── util
    ├── arc_cell.rs
    ├── atomic_option.rs
    └── mod.rs

TODO

  • basic operators,factories,Schedulers
  • refactor towards zero-cost abstractions
  • WIP: advanced operators,factories,Schedulers
  • WIP: provide practical examples
  • docs
  • release a crate