pub trait ReceiverExt<T: Message>: Sized {
// Required methods
fn stream(self) -> StreamBuilder<T>;
fn filter<F>(self, predicate: F) -> StreamBuilder<T>
where F: Fn(&T) -> bool + Send + Sync + 'static;
fn map<F>(self, mapper: F) -> StreamBuilder<T>
where F: Fn(T) -> T + Send + Sync + 'static;
fn debounce(self, duration: Duration) -> StreamBuilder<T>;
fn throttle(self, duration: Duration) -> StreamBuilder<T>;
fn latest(self) -> StreamBuilder<T>;
fn batch(self, size: usize, timeout: Duration) -> BatchBuilder<T>
where T: Clone;
fn zip<U>(self, other: Receiver<U>) -> Receiver<(T, U)>
where U: Message + Send + 'static;
fn window(self, window_duration: Duration) -> Receiver<Vec<T>>
where T: Clone;
}Expand description
Extension trait to add stream combinator methods to Receiver
Required Methods§
Sourcefn stream(self) -> StreamBuilder<T>
fn stream(self) -> StreamBuilder<T>
Start building a stream pipeline
Sourcefn filter<F>(self, predicate: F) -> StreamBuilder<T>
fn filter<F>(self, predicate: F) -> StreamBuilder<T>
Filter messages based on a predicate
Sourcefn map<F>(self, mapper: F) -> StreamBuilder<T>
fn map<F>(self, mapper: F) -> StreamBuilder<T>
Transform messages using a mapping function
Sourcefn debounce(self, duration: Duration) -> StreamBuilder<T>
fn debounce(self, duration: Duration) -> StreamBuilder<T>
Debounce messages - ignore duplicates within a time window
Sourcefn throttle(self, duration: Duration) -> StreamBuilder<T>
fn throttle(self, duration: Duration) -> StreamBuilder<T>
Throttle messages to a maximum rate
Sourcefn latest(self) -> StreamBuilder<T>
fn latest(self) -> StreamBuilder<T>
Keep only the latest message
Sourcefn batch(self, size: usize, timeout: Duration) -> BatchBuilder<T>where
T: Clone,
fn batch(self, size: usize, timeout: Duration) -> BatchBuilder<T>where
T: Clone,
Batch messages together
Collects messages into batches of size size, or until timeout
elapses, whichever comes first. Returns a BatchBuilder which can
be built into a Receiver<Vec
§Arguments
size- Maximum number of messages per batchtimeout- Maximum time to wait before emitting a partial batch
§Example
// Collect messages into batches of 10, or every 1 second
let mut batched = ctx.subscribe(sensor::IMU)
.await?
.batch(10, Duration::from_secs(1))
.build();
while let Some(batch) = batched.recv().await {
println!("Received batch of {} messages", batch.len());
// Process batch efficiently
}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.