Observable

Trait Observable 

Source
pub trait Observable: Sized {
    type Item;
    type Err;

Show 50 methods // Provided methods fn first(self) -> TakeOp<Self> { ... } fn first_or(self, default: Self::Item) -> DefaultIfEmptyOp<TakeOp<Self>> { ... } fn last_or( self, default: Self::Item, ) -> DefaultIfEmptyOp<LastOp<Self, Self::Item>> { ... } fn element_at(self, nth: u32) -> TakeOp<SkipOp<Self>> { ... } fn ignore_elements(self) -> FilterOp<Self, fn(&Self::Item) -> bool> { ... } fn all<F>( self, pred: F, ) -> DefaultIfEmptyOp<TakeOp<FilterOp<MapOp<Self, F>, fn(&bool) -> bool>>> where F: Fn(Self::Item) -> bool { ... } fn contains(self, target: Self::Item) -> ContainsOp<Self, Self::Item> { ... } fn last(self) -> LastOp<Self, Self::Item> { ... } fn finalize<F>(self, f: F) -> FinalizeOp<Self, F> where F: FnMut() { ... } fn flatten<Inner, A>(self) -> FlattenOp<Self, Inner> where Inner: Observable<Item = A, Err = Self::Err> { ... } fn flat_map<Inner, B, F>(self, f: F) -> FlatMapOp<Self, Inner, F> where Inner: Observable<Item = B, Err = Self::Err>, F: Fn(Self::Item) -> Inner { ... } fn group_by<D, Item, Key>(self, discr: D) -> GroupByOp<Self, D> where D: FnMut(&Item) -> Key { ... } fn map<B, F>(self, f: F) -> MapOp<Self, F> where F: Fn(Self::Item) -> B { ... } fn map_to<B>(self, value: B) -> MapToOp<Self, B> { ... } fn merge<S>(self, o: S) -> MergeOp<Self, S> where S: Observable<Item = Self::Item, Err = Self::Err> { ... } fn merge_all(self, concurrent: usize) -> MergeAllOp<Self> { ... } fn filter<F>(self, filter: F) -> FilterOp<Self, F> where F: Fn(&Self::Item) -> bool { ... } fn filter_map<F, SourceItem, Item>(self, f: F) -> FilterMapOp<Self, F> where F: FnMut(SourceItem) -> Option<Item> { ... } fn box_it<O: IntoBox<Self>>(self) -> BoxOp<O> where BoxOp<O>: Observable<Item = Self::Item, Err = Self::Err> { ... } fn skip(self, count: u32) -> SkipOp<Self> { ... } fn skip_while<F>(self, callback: F) -> SkipWhileOp<Self, F> where F: FnMut(&Self::Item) -> bool { ... } fn skip_last(self, count: usize) -> SkipLastOp<Self> { ... } fn take(self, count: u32) -> TakeOp<Self> { ... } fn take_until<T>(self, notifier: T) -> TakeUntilOp<Self, T> { ... } fn take_while<F>(self, callback: F) -> TakeWhileOp<Self, F> where F: FnMut(&Self::Item) -> bool { ... } fn take_last(self, count: usize) -> TakeLastOp<Self> { ... } fn sample<O>(self, sampling: O) -> SampleOp<Self, O> where O: Observable { ... } fn scan_initial<OutputItem, BinaryOp>( self, initial_value: OutputItem, binary_op: BinaryOp, ) -> ScanOp<Self, BinaryOp, OutputItem> where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Clone { ... } fn scan<OutputItem, BinaryOp>( self, binary_op: BinaryOp, ) -> ScanOp<Self, BinaryOp, OutputItem> where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Default + Clone { ... } fn reduce_initial<OutputItem, BinaryOp>( self, initial: OutputItem, binary_op: BinaryOp, ) -> ReduceOp<Self, BinaryOp, OutputItem> where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Clone { ... } fn reduce<OutputItem, BinaryOp>( self, binary_op: BinaryOp, ) -> DefaultIfEmptyOp<LastOp<ScanOp<Self, BinaryOp, OutputItem>, OutputItem>> where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Default + Clone { ... } fn max(self) -> MinMaxOp<Self, Self::Item> where Self::Item: Clone + Send + PartialOrd<Self::Item> { ... } fn min(self) -> MinMaxOp<Self, Self::Item> where Self::Item: Clone + Send + PartialOrd<Self::Item> { ... } fn sum(self) -> SumOp<Self, Self::Item> where Self::Item: Clone + Default + Add<Self::Item, Output = Self::Item> { ... } fn count(self) -> CountOp<Self, Self::Item> { ... } fn average(self) -> AverageOp<Self, Self::Item> where Self::Item: Clone + Send + Default + Add<Self::Item, Output = Self::Item> + Mul<f64, Output = Self::Item> { ... } fn publish<Subject: Default>(self) -> ConnectableObservable<Self, Subject> { ... } fn share<Subject, Inner>( self, ) -> RefCount<Inner, ConnectableObservable<Self, Subject>> where Inner: RefCountCreator<Connectable = ConnectableObservable<Self, Subject>>, Subject: Default, Self: Clone { ... } fn delay<SD>(self, dur: Duration, scheduler: SD) -> DelayOp<Self, SD> { ... } fn delay_at<SD>(self, at: Instant, scheduler: SD) -> DelayOp<Self, SD> { ... } fn subscribe_on<SD>(self, scheduler: SD) -> SubscribeOnOP<Self, SD> { ... } fn observe_on<SD>(self, scheduler: SD) -> ObserveOnOp<Self, SD> { ... } fn debounce<SD>( self, duration: Duration, scheduler: SD, ) -> DebounceOp<Self, SD> { ... } fn throttle_time<SD>( self, duration: Duration, edge: ThrottleEdge, scheduler: SD, ) -> ThrottleTimeOp<Self, SD> { ... } fn distinct(self) -> DistinctOp<Self> { ... } fn zip<U>(self, other: U) -> ZipOp<Self, U> where U: Observable { ... } fn default_if_empty( self, default_value: Self::Item, ) -> DefaultIfEmptyOp<Self> { ... } fn buffer_with_count(self, count: usize) -> BufferWithCountOp<Self> { ... } fn buffer_with_time<S>( self, time: Duration, scheduler: S, ) -> BufferWithTimeOp<Self, S> { ... } fn buffer_with_count_and_time<S>( self, count: usize, time: Duration, scheduler: S, ) -> BufferWithCountOrTimerOp<Self, S> { ... }
}

Required Associated Types§

Provided Methods§

Source

fn first(self) -> TakeOp<Self>

emit only the first item emitted by an Observable

Source

fn first_or(self, default: Self::Item) -> DefaultIfEmptyOp<TakeOp<Self>>

emit only the first item emitted by an Observable

Source

fn last_or( self, default: Self::Item, ) -> DefaultIfEmptyOp<LastOp<Self, Self::Item>>

Emit only the last final item emitted by a source observable or a default item given.

Completes right after emitting the single item. Emits error when source observable emits it.

§Examples
use rxrust::prelude::*;

observable::empty()
  .last_or(1234)
  .subscribe(|v| println!("{}", v));

// print log:
// 1234
Source

fn element_at(self, nth: u32) -> TakeOp<SkipOp<Self>>

Emit only item n (0-indexed) emitted by an Observable

Source

fn ignore_elements(self) -> FilterOp<Self, fn(&Self::Item) -> bool>

Do not emit any items from an Observable but mirror its termination notification

Source

fn all<F>( self, pred: F, ) -> DefaultIfEmptyOp<TakeOp<FilterOp<MapOp<Self, F>, fn(&bool) -> bool>>>
where F: Fn(Self::Item) -> bool,

Determine whether all items emitted by an Observable meet some criteria

Source

fn contains(self, target: Self::Item) -> ContainsOp<Self, Self::Item>

Determine whether an Observable emits a particular item or not

Source

fn last(self) -> LastOp<Self, Self::Item>

Emits only last final item emitted by a source observable.

Completes right after emitting the single last item, or when source observable completed, being an empty one. Emits error when source observable emits it.

§Examples
use rxrust::prelude::*;

observable::from_iter(0..100)
  .last()
  .subscribe(|v| println!("{}", v));

// print log:
// 99
Source

fn finalize<F>(self, f: F) -> FinalizeOp<Self, F>
where F: FnMut(),

Call a function when observable completes, errors or is unsubscribed from.

Source

fn flatten<Inner, A>(self) -> FlattenOp<Self, Inner>
where Inner: Observable<Item = A, Err = Self::Err>,

Creates an Observable that combines all the emissions from Observables that get emitted from an Observable.

§Example
let mut source = LocalSubject::new();
let numbers = LocalSubject::new();
// create a even stream by filter
let even = numbers.clone().filter((|v| *v % 2 == 0) as fn(&i32) -> bool);
// create an odd stream by filter
let odd = numbers.clone().filter((|v| *v % 2 != 0) as fn(&i32) -> bool);

// merge odd and even stream again
let out = source.clone().flatten();

source.next(even);
source.next(odd);

// attach observers
out.subscribe(|v: i32| println!("{} ", v));
Source

fn flat_map<Inner, B, F>(self, f: F) -> FlatMapOp<Self, Inner, F>
where Inner: Observable<Item = B, Err = Self::Err>, F: Fn(Self::Item) -> Inner,

Applies given function to each item emitted by this Observable, where that function returns an Observable that itself emits items. It then merges the emissions of these resulting Observables, emitting these merged results as its own sequence.

Source

fn group_by<D, Item, Key>(self, discr: D) -> GroupByOp<Self, D>
where D: FnMut(&Item) -> Key,

Groups items emited by the source Observable into Observables. Each emited Observable emits items matching the key returned by the discriminator function.

§Example
use rxrust::prelude::*;

#[derive(Clone)]
struct Person {
  name: String,
  age: u32,
}

observable::from_iter([
  Person{ name: String::from("John"), age: 26 },
  Person{ name: String::from("Anne"), age: 28 },
  Person{ name: String::from("Gregory"), age: 24 },
  Person{ name: String::from("Alice"), age: 28 },
])
.group_by(|person: &Person| person.age)
.subscribe(|group| {
  group
  .reduce(|acc, person| format!("{} {}", acc, person.name))
  .subscribe(|result| println!("{}", result));
});

// Prints:
//  John
//  Anne Alice
//  Gregory
Source

fn map<B, F>(self, f: F) -> MapOp<Self, F>
where F: Fn(Self::Item) -> B,

Creates a new stream which calls a closure on each element and uses its return as the value.

Source

fn map_to<B>(self, value: B) -> MapToOp<Self, B>

Maps emissions to a constant value.

Source

fn merge<S>(self, o: S) -> MergeOp<Self, S>
where S: Observable<Item = Self::Item, Err = Self::Err>,

combine two Observables into one by merging their emissions

§Example
let numbers = LocalSubject::new();
// create a even stream by filter
let even = numbers.clone().filter(|v| *v % 2 == 0);
// create an odd stream by filter
let odd = numbers.clone().filter(|v| *v % 2 != 0);

// merge odd and even stream again
let merged = even.merge(odd);

// attach observers
merged.subscribe(|v: &i32| println!("{} ", v));
Source

fn merge_all(self, concurrent: usize) -> MergeAllOp<Self>

Converts a higher-order Observable into a first-order Observable which concurrently delivers all values that are emitted on the inner Observables.

§Example
let mut local = LocalPool::new();
observable::from_iter(
  (0..3)
    .map(|_| interval(Duration::from_millis(1), local.spawner()).take(5)),
)
.merge_all(2)
.subscribe(move |i| println!("{}", i));
local.run();
Source

fn filter<F>(self, filter: F) -> FilterOp<Self, F>
where F: Fn(&Self::Item) -> bool,

Emit only those items from an Observable that pass a predicate test

§Example
use rxrust:: prelude::*;

let mut coll = vec![];
let coll_clone = coll.clone();

observable::from_iter(0..10)
  .filter(|v| *v % 2 == 0)
  .subscribe(|v| { coll.push(v); });

// only even numbers received.
assert_eq!(coll, vec![0, 2, 4, 6, 8]);
Source

fn filter_map<F, SourceItem, Item>(self, f: F) -> FilterMapOp<Self, F>
where F: FnMut(SourceItem) -> Option<Item>,

The closure must return an Option. filter_map creates an iterator which calls this closure on each element. If the closure returns Some(element), then that element is returned. If the closure returns None, it will try again, and call the closure on the next element, seeing if it will return Some.

Why filter_map and not just filter and map? The key is in this part:

If the closure returns Some(element), then that element is returned.

In other words, it removes the Option layer automatically. If your mapping is already returning an Option and you want to skip over Nones, then filter_map is much, much nicer to use.

§Examples
 let mut res: Vec<i32> = vec![];
  observable::from_iter(["1", "lol", "3", "NaN", "5"].iter())
  .filter_map(|s: &&str| s.parse().ok())
  .subscribe(|v| res.push(v));

assert_eq!(res, [1, 3, 5]);
Source

fn box_it<O: IntoBox<Self>>(self) -> BoxOp<O>
where BoxOp<O>: Observable<Item = Self::Item, Err = Self::Err>,

box an observable to a safety object and convert it to a simple type BoxOp, which only care Item and Err Observable emitted.

§Example
use rxrust::prelude::*;
use ops::box_it::LocalBoxOp;

let mut boxed: LocalBoxOp<'_, i32, ()> = observable::of(1)
  .map(|v| v).box_it();

// BoxOp can box any observable type
boxed = observable::empty().box_it();

boxed.subscribe(|_| {});
Source

fn skip(self, count: u32) -> SkipOp<Self>

Ignore the first count values emitted by the source Observable.

skip returns an Observable that ignore the first count values emitted by the source Observable. If the source emits fewer than count values then 0 of its values are emitted. After that, it completes, regardless if the source completes.

§Example

Ignore the first 5 seconds of an infinite 1-second interval Observable


observable::from_iter(0..10).skip(5).subscribe(|v| println!("{}", v));
// print logs:
// 6
// 7
// 8
// 9
// 10
Source

fn skip_while<F>(self, callback: F) -> SkipWhileOp<Self, F>
where F: FnMut(&Self::Item) -> bool,

Ignore values while result of a callback is true.

skip_while returns an Observable that ignores values while result of an callback is true emitted by the source Observable.

§Example

Suppress the first 5 items of an infinite 1-second interval Observable


observable::from_iter(0..10)
  .skip_while(|v| v < &5)
  .subscribe(|v| println!("{}", v));

// print logs:
// 5
// 6
// 7
// 8
// 9
Source

fn skip_last(self, count: usize) -> SkipLastOp<Self>

Ignore the last count values emitted by the source Observable.

skip_last returns an Observable that ignore the last count values emitted by the source Observable. If the source emits fewer than count values then 0 of its values are emitted. It will not emit values until source Observable complete.

§Example

Skip the last 5 seconds of an infinite 1-second interval Observable


observable::from_iter(0..10)
  .skip_last(5)
  .subscribe(|v| println!("{}", v));

// print logs:
// 0
// 1
// 2
// 3
// 4
Source

fn take(self, count: u32) -> TakeOp<Self>

Emits only the first count values emitted by the source Observable.

take returns an Observable that emits only the first count values emitted by the source Observable. If the source emits fewer than count values then all of its values are emitted. After that, it completes, regardless if the source completes.

§Example

Take the first 5 seconds of an infinite 1-second interval Observable


observable::from_iter(0..10).take(5).subscribe(|v| println!("{}", v));
// print logs:
// 0
// 1
// 2
// 3
// 4
Source

fn take_until<T>(self, notifier: T) -> TakeUntilOp<Self, T>

Emits the values emitted by the source Observable until a notifier Observable emits a value.

take_until subscribes and begins mirroring the source Observable. It also monitors a second Observable, notifier that you provide. If the notifier emits a value, the output Observable stops mirroring the source Observable and completes. If the notifier doesn’t emit any value and completes then take_until will pass all values.

Source

fn take_while<F>(self, callback: F) -> TakeWhileOp<Self, F>
where F: FnMut(&Self::Item) -> bool,

Emits values while result of an callback is true.

take_while returns an Observable that emits values while result of an callback is true emitted by the source Observable. It will not emit values until source Observable complete.

§Example

Take the first 5 seconds of an infinite 1-second interval Observable


observable::from_iter(0..10)
  .take_while(|v| v < &5)
.subscribe(|v| println!("{}", v));
// print logs:
// 0
// 1
// 2
// 3
// 4
Source

fn take_last(self, count: usize) -> TakeLastOp<Self>

Emits only the last count values emitted by the source Observable.

take_last returns an Observable that emits only the last count values emitted by the source Observable. If the source emits fewer than count values then all of its values are emitted. It will not emit values until source Observable complete.

§Example

Take the last 5 seconds of an infinite 1-second interval Observable


observable::from_iter(0..10)
  .take_last(5)
.subscribe(|v| println!("{}", v));
// print logs:
// 5
// 6
// 7
// 8
// 9
Source

fn sample<O>(self, sampling: O) -> SampleOp<Self, O>
where O: Observable,

Emits item it has most recently emitted since the previous sampling

It will emit values when sampling observable complete.

#Example Sampling every 5ms of an infinite 1ms interval Observable

use rxrust::prelude::*;
use std::time::Duration;
use futures::executor::LocalPool;

let mut local_scheduler = LocalPool::new();
let spawner = local_scheduler.spawner();
observable::interval(Duration::from_millis(2), spawner.clone())
  .sample(observable::interval(Duration::from_millis(5), spawner))
  .take(5)
  .subscribe(move |v| println!("{}", v));

local_scheduler.run();
// print logs:
// 1
// 4
// 6
// 9
// ...
Source

fn scan_initial<OutputItem, BinaryOp>( self, initial_value: OutputItem, binary_op: BinaryOp, ) -> ScanOp<Self, BinaryOp, OutputItem>
where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Clone,

The Scan operator applies a function to the first item emitted by the source observable and then emits the result of that function as its own first emission. It also feeds the result of the function back into the function along with the second item emitted by the source observable in order to generate its second emission. It continues to feed back its own subsequent emissions along with the subsequent emissions from the source Observable in order to create the rest of its sequence.

Applies a binary operator closure to each item emitted from source observable and emits successive values.

Completes when source observable completes. Emits error when source observable emits it.

This version starts with an user-specified initial value for when the binary operator is called with the first item processed.

§Arguments
  • initial_value - An initial value to start the successive accumulations from.
  • binary_op - A closure or function acting as a binary operator.
§Examples
use rxrust::prelude::*;

observable::from_iter(vec![1, 1, 1, 1, 1])
  .scan_initial(100, |acc, v| acc + v)
  .subscribe(|v| println!("{}", v));

// print log:
// 101
// 102
// 103
// 104
// 105
Source

fn scan<OutputItem, BinaryOp>( self, binary_op: BinaryOp, ) -> ScanOp<Self, BinaryOp, OutputItem>
where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Default + Clone,

Works like scan_initial but starts with a value defined by a Default trait for the first argument binary_op operator operates on.

§Arguments
  • binary_op - A closure or function acting as a binary operator.
Source

fn reduce_initial<OutputItem, BinaryOp>( self, initial: OutputItem, binary_op: BinaryOp, ) -> ReduceOp<Self, BinaryOp, OutputItem>
where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Clone,

Apply a function to each item emitted by an observable, sequentially, and emit the final value, after source observable completes.

Emits error when source observable emits it.

§Arguments
  • initial - An initial value to start the successive reduction from.
  • binary_op - A closure acting as a binary (folding) operator.
§Examples
use rxrust::prelude::*;

observable::from_iter(vec![1, 1, 1, 1, 1])
  .reduce_initial(100, |acc, v| acc + v)
  .subscribe(|v| println!("{}", v));

// print log:
// 105
Source

fn reduce<OutputItem, BinaryOp>( self, binary_op: BinaryOp, ) -> DefaultIfEmptyOp<LastOp<ScanOp<Self, BinaryOp, OutputItem>, OutputItem>>
where BinaryOp: Fn(OutputItem, Self::Item) -> OutputItem, OutputItem: Default + Clone,

Works like reduce_initial but starts with a value defined by a Default trait for the first argument f operator operates on.

§Arguments
  • binary_op - A closure acting as a binary operator.
Source

fn max(self) -> MinMaxOp<Self, Self::Item>
where Self::Item: Clone + Send + PartialOrd<Self::Item>,

Emits the item from the source observable that had the maximum value.

Emits error when source observable emits it.

§Examples
use rxrust::prelude::*;

observable::from_iter(vec![3., 4., 7., 5., 6.])
  .max()
  .subscribe(|v| println!("{}", v));

// print log:
// 7
Source

fn min(self) -> MinMaxOp<Self, Self::Item>
where Self::Item: Clone + Send + PartialOrd<Self::Item>,

Emits the item from the source observable that had the minimum value.

Emits error when source observable emits it.

§Examples
use rxrust::prelude::*;

observable::from_iter(vec![3., 4., 7., 5., 6.])
  .min()
  .subscribe(|v| println!("{}", v));

// print log:
// 3
Source

fn sum(self) -> SumOp<Self, Self::Item>
where Self::Item: Clone + Default + Add<Self::Item, Output = Self::Item>,

Calculates the sum of numbers emitted by an source observable and emits this sum when source completes.

Emits zero when source completed as an and empty sequence. Emits error when source observable emits it.

§Examples
use rxrust::prelude::*;

observable::from_iter(vec![1, 1, 1, 1, 1])
  .sum()
  .subscribe(|v| println!("{}", v));

// p rint log:
// 5
Source

fn count(self) -> CountOp<Self, Self::Item>

Emits the number of items emitted by a source observable when this source completes.

The output type of this operator is fixed to usize.

Emits zero when source completed as an and empty sequence. Emits error when source observable emits it.

§Examples
use rxrust::prelude::*;

observable::from_iter(vec!['1', '7', '3', '0', '4'])
  .count()
  .subscribe(|v| println!("{}", v));

// print log:
// 5
Source

fn average(self) -> AverageOp<Self, Self::Item>
where Self::Item: Clone + Send + Default + Add<Self::Item, Output = Self::Item> + Mul<f64, Output = Self::Item>,

Calculates the sum of numbers emitted by an source observable and emits this sum when source completes.

Emits zero when source completed as an and empty sequence. Emits error when source observable emits it.

§Examples
use rxrust::prelude::*;

observable::from_iter(vec![3., 4., 5., 6., 7.])
  .average()
  .subscribe(|v| println!("{}", v));

// print log:
// 5
Source

fn publish<Subject: Default>(self) -> ConnectableObservable<Self, Subject>

Returns a ConnectableObservable. A ConnectableObservable Observable resembles an ordinary Observable, except that it does not begin emitting items when it is subscribed to, but only when the Connect operator is applied to it. In this way you can wait for all intended observers to subscribe to the Observable before the Observable begins emitting items.

Source

fn share<Subject, Inner>( self, ) -> RefCount<Inner, ConnectableObservable<Self, Subject>>
where Inner: RefCountCreator<Connectable = ConnectableObservable<Self, Subject>>, Subject: Default, Self: Clone,

Returns a new Observable that multicast (shares) the original Observable. As long as there is at least one Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream hot. This is an alias for publish().ref_count()

Source

fn delay<SD>(self, dur: Duration, scheduler: SD) -> DelayOp<Self, SD>

Delays the emission of items from the source Observable by a given timeout or until a given Instant.

Source

fn delay_at<SD>(self, at: Instant, scheduler: SD) -> DelayOp<Self, SD>

Source

fn subscribe_on<SD>(self, scheduler: SD) -> SubscribeOnOP<Self, SD>

Specify the Scheduler on which an Observable will operate

With SubscribeON you can decide what type of scheduler a specific Observable will be using when it is subscribed to.

Schedulers control the speed and order of emissions to observers from an Observable stream.

§Example

Given the following code:

use rxrust::prelude::*;

let a = observable::from_iter(1..5);
let b = observable::from_iter(5..10);
a.merge(b).subscribe(|v| print!("{} ", v));

Both Observable a and b will emit their values directly and synchronously once they are subscribed to. This will result in the output of 1 2 3 4 5 6 7 8 9.

But if we instead use the subscribe_on operator declaring that we want to use the new thread scheduler for values emitted by Observable a:

use rxrust::prelude::*;
use std::thread;
use futures::executor::ThreadPool;

let pool = ThreadPool::new().unwrap();
let a = observable::from_iter(1..5).subscribe_on(pool);
let b = observable::from_iter(5..10);
a.merge(b).into_shared().subscribe(|v|{
  let handle = thread::current();
  print!("{}({:?}) ", v, handle.id())
});

The output will instead by `1(thread 1) 2(thread 1) 3(thread 1) 4(thread

  1. 5(thread 2) 6(thread 2) 7(thread 2) 8(thread 2) 9(thread id2). The reason for this is that Observable bemits its values directly like before, but the emissions fromaare scheduled on a new thread because we are now using theNewThread` Scheduler for that specific Observable.
Source

fn observe_on<SD>(self, scheduler: SD) -> ObserveOnOp<Self, SD>

Re-emits all notifications from source Observable with specified scheduler.

ObserveOn is an operator that accepts a scheduler as the parameter, which will be used to reschedule notifications emitted by the source Observable.

Source

fn debounce<SD>(self, duration: Duration, scheduler: SD) -> DebounceOp<Self, SD>

Emits a value from the source Observable only after a particular time span has passed without another source emission.

Source

fn throttle_time<SD>( self, duration: Duration, edge: ThrottleEdge, scheduler: SD, ) -> ThrottleTimeOp<Self, SD>

Emits a value from the source Observable, then ignores subsequent source values for duration milliseconds, then repeats this process.

#Example

use rxrust::{ prelude::*, ops::throttle_time::ThrottleEdge };
use std::time::Duration;
use futures::executor::LocalPool;

let mut local_scheduler = LocalPool::new();
let spawner = local_scheduler.spawner();
observable::interval(Duration::from_millis(1), spawner.clone())
  .throttle_time(Duration::from_millis(9), ThrottleEdge::Leading, spawner)
  .take(5)
  .subscribe(move |v| println!("{}", v));

local_scheduler.run();
Source

fn distinct(self) -> DistinctOp<Self>

Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.

Source

fn zip<U>(self, other: U) -> ZipOp<Self, U>
where U: Observable,

‘Zips up’ two observable into a single observable of pairs.

zip() returns a new observable that will emit over two other observables, returning a tuple where the first element comes from the first observable, and the second element comes from the second observable.

In other words, it zips two observables together, into a single one.

Source

fn default_if_empty(self, default_value: Self::Item) -> DefaultIfEmptyOp<Self>

Emits default value if Observable completed with empty result

#Example

use rxrust::prelude::*;

observable::empty()
  .default_if_empty(5)
  .subscribe(|v| println!("{}", v));

// Prints:
// 5
Source

fn buffer_with_count(self, count: usize) -> BufferWithCountOp<Self>

Buffers emitted values of type T in a Vec and emits that Vec as soon as the buffer’s size equals the given count. On complete, if the buffer is not empty, it will be emitted. On error, the buffer will be discarded.

The operator never returns an empty buffer.

#Example

use rxrust::prelude::*;

observable::from_iter(0..6)
  .buffer_with_count(3)
  .subscribe(|vec| println!("{:?}", vec));

// Prints:
// [0, 1, 2]
// [3, 4, 5]
Source

fn buffer_with_time<S>( self, time: Duration, scheduler: S, ) -> BufferWithTimeOp<Self, S>

Buffers emitted values of type T in a Vec and emits that Vec periodically.

On complete, if the buffer is not empty, it will be emitted. On error, the buffer will be discarded.

The operator never returns an empty buffer.

#Example

use rxrust::prelude::*;
use std::time::Duration;
use futures::executor::ThreadPool;

let pool = ThreadPool::new().unwrap();

observable::create(|mut subscriber| {
  subscriber.next(0);
  subscriber.next(1);
  std::thread::sleep(Duration::from_millis(100));
  subscriber.next(2);
  subscriber.next(3);
  subscriber.complete();
})
  .buffer_with_time(Duration::from_millis(50), pool)
  .into_shared()
  .subscribe(|vec| println!("{:?}", vec));

// Prints:
// [0, 1]
// [2, 3]
Source

fn buffer_with_count_and_time<S>( self, count: usize, time: Duration, scheduler: S, ) -> BufferWithCountOrTimerOp<Self, S>

Buffers emitted values of type T in a Vec and emits that Vec either if the buffer’s size equals count, or periodically. This operator combines the functionality of buffer_with_count and buffer_with_time.

#Example

use rxrust::prelude::*;
use std::time::Duration;
use futures::executor::ThreadPool;

let pool = ThreadPool::new().unwrap();

observable::create(|mut subscriber| {
  subscriber.next(0);
  subscriber.next(1);
  subscriber.next(2);
  std::thread::sleep(Duration::from_millis(100));
  subscriber.next(3);
  subscriber.next(4);
  subscriber.complete();
})
  .buffer_with_count_and_time(2, Duration::from_millis(50), pool)
  .into_shared()
  .subscribe(|vec| println!("{:?}", vec));

// Prints:
// [0, 1]
// [2]
// [3, 4]

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, Item, Err> Observable for LocalBoxOp<'a, Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<'a, Item, Err> Observable for LocalCloneBoxOp<'a, Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<'a, Item, Err> Observable for LocalBehaviorSubject<'a, Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<'a, Item, Err> Observable for LocalSubject<'a, Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<'a, Item, Err, S> Observable for LocalRefCount<'a, S, Item, Err>
where S: LocalObservable<'a, Item = Item, Err = Err>,

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<'a, Item, S, F> Observable for FilterMapOp<S, F>
where S: Observable, F: FnMut(S::Item) -> Option<Item>,

Source§

type Item = Item

Source§

type Err = <S as Observable>::Err

Source§

impl<A, B> Observable for ZipOp<A, B>
where A: Observable, B: Observable<Err = A::Err>,

Source§

type Item = (<A as Observable>::Item, <B as Observable>::Item)

Source§

type Err = <A as Observable>::Err

Source§

impl<Emit> Observable for ObservableBase<Emit>
where Emit: Emitter,

Source§

type Item = <Emit as Emitter>::Item

Source§

type Err = <Emit as Emitter>::Err

Source§

impl<Item, Err> Observable for SharedBoxOp<Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<Item, Err> Observable for SharedCloneBoxOp<Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<Item, Err> Observable for SharedBehaviorSubject<Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<Item, Err> Observable for SharedSubject<Item, Err>

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<Item, Err, S> Observable for SharedRefCount<S, Item, Err>
where S: SharedObservable<Item = Item, Err = Err>,

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<Item, S> Observable for LastOp<S, Item>
where S: Observable<Item = Item>,

Source§

type Item = Item

Source§

type Err = <S as Observable>::Err

Source§

impl<Item, S, M> Observable for MapOp<S, M>
where S: Observable, M: FnMut(S::Item) -> Item,

Source§

type Item = Item

Source§

type Err = <S as Observable>::Err

Source§

impl<Outer, Inner, Item, Err> Observable for FlattenOp<Outer, Inner>
where Outer: Observable<Item = Inner, Err = Err>, Inner: Observable<Item = Item, Err = Err>,

Source§

type Item = Item

Source§

type Err = Err

Source§

impl<OutputItem, Source, BinaryOp> Observable for ScanOp<Source, BinaryOp, OutputItem>
where Source: Observable, OutputItem: Clone, BinaryOp: FnMut(OutputItem, Source::Item) -> OutputItem,

Source§

type Item = OutputItem

Source§

type Err = <Source as Observable>::Err

Source§

impl<S1, S2> Observable for MergeOp<S1, S2>
where S1: Observable, S2: Observable<Item = S1::Item, Err = S1::Err>,

Source§

type Item = <S1 as Observable>::Item

Source§

type Err = <S1 as Observable>::Err

Source§

impl<S> Observable for BufferWithCountOp<S>
where S: Observable,

Source§

type Item = Vec<<S as Observable>::Item>

Source§

type Err = <S as Observable>::Err

Source§

impl<S> Observable for DefaultIfEmptyOp<S>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S> Observable for DistinctOp<S>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S> Observable for MergeAllOp<S>
where S: Observable, S::Item: Observable,

Source§

impl<S> Observable for SkipOp<S>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S> Observable for SkipLastOp<S>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S> Observable for TakeOp<S>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S> Observable for TakeLastOp<S>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S> Observable for Shared<S>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, B> Observable for MapToOp<S, B>
where S: Observable,

Source§

type Item = B

Source§

type Err = <S as Observable>::Err

Source§

impl<S, F> Observable for FilterOp<S, F>
where S: Observable, F: FnMut(&S::Item) -> bool,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, F> Observable for FinalizeOp<S, F>
where S: Observable, F: FnMut(),

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, F> Observable for SkipWhileOp<S, F>
where S: Observable, F: FnMut(&S::Item) -> bool,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, F> Observable for TakeWhileOp<S, F>
where S: Observable, F: FnMut(&S::Item) -> bool,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, Item> Observable for ContainsOp<S, Item>
where S: Observable<Item = Item>,

Source§

impl<S, N> Observable for TakeUntilOp<S, N>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, SD> Observable for DebounceOp<S, SD>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, SD> Observable for DelayOp<S, SD>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, SD> Observable for ObserveOnOp<S, SD>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, SD> Observable for SubscribeOnOP<S, SD>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, SD> Observable for ThrottleTimeOp<S, SD>
where S: Observable,

Source§

type Item = <S as Observable>::Item

Source§

type Err = <S as Observable>::Err

Source§

impl<S, Scheduler> Observable for BufferWithCountOrTimerOp<S, Scheduler>
where S: Observable,

Source§

type Item = Vec<<S as Observable>::Item>

Source§

type Err = <S as Observable>::Err

Source§

impl<S, Scheduler> Observable for BufferWithTimeOp<S, Scheduler>
where S: Observable,

Source§

type Item = Vec<<S as Observable>::Item>

Source§

type Err = <S as Observable>::Err

Source§

impl<Source, Discr, Key> Observable for GroupByOp<Source, Discr>
where Source: Observable, Discr: FnMut(&Source::Item) -> Key, Key: Hash + Eq,

Source§

type Item = GroupObservable<Source, Discr, Key>

Source§

type Err = <Source as Observable>::Err

Source§

impl<Source, Discr, Key> Observable for GroupObservable<Source, Discr, Key>
where Source: Observable,

Source§

type Item = <Source as Observable>::Item

Source§

type Err = <Source as Observable>::Err

Source§

impl<Source, Sampling> Observable for SampleOp<Source, Sampling>
where Source: Observable, Sampling: Observable,

Source§

type Item = <Source as Observable>::Item

Source§

type Err = <Source as Observable>::Err

Source§

impl<Source, Subject> Observable for ConnectableObservable<Source, Subject>
where Source: Observable,

Source§

type Item = <Source as Observable>::Item

Source§

type Err = <Source as Observable>::Err