change_stream

Crates.iochange_stream
lib.rschange_stream
version0.1.0
sourcesrc
created_at2023-06-29 18:53:31.625126
updated_at2023-06-29 18:53:31.625126
descriptionA Stream that only emits if the value is different.
homepage
repositoryhttps://github.com/andrewlowndes/change_stream
max_upload_size
id903582
size19,413
Andrew Lowndes (andrewlowndes)

documentation

README

Change stream

A Stream that only emits if the value is different.

Important

  • The stream item is stored in the struct by Cloning so the stream Item must implement Clone
  • The comparison for the items is done via an equality check so the Item must implement PartialEq with itself

Example usage

  • Add to your Cargo.toml file
[dependencies]
change_stream = "0.1.0"
  • Import the StreamChanged trait and call .changed() on an existing stream:
use change_stream::StreamChanged;
use futures::{stream::iter, StreamExt};

#[tokio::main]
async fn main() {
    let a = iter([1, 1, 2]);

    a.changed().for_each(|a| async move {
        dbg!(a); //will only emit 1 and 2
    }).await;
}
Commit count: 2

cargo fmt