#iterator #raii #automatic #invoke #stream #action #async

stream-guard

RAII wrapper around Stream that invokes a custom action on drop

1 stable release

1.0.0 May 31, 2024

#1102 in Asynchronous

Download history 3/week @ 2024-11-16 4/week @ 2024-11-23 7/week @ 2024-11-30 19/week @ 2024-12-07 3/week @ 2024-12-14 1/week @ 2025-02-01 6/week @ 2025-02-22 78/week @ 2025-03-01

85 downloads per month
Used in 8 crates (via lighthouse-client)

MIT license

6KB

Stream Guard

crates.io Build

A small RAII wrapper around a Stream (asynchronous iterator) that automatically invokes a user-defined action upon being dropped.


lib.rs:

A small RAII wrapper around a Stream that automatically invokes a user-defined action upon being dropped.

For example:

#
async fn f() {
    let mut s = stream::iter(0..3).guard(|| println!("Dropped!"));
    while let Some(i) = s.next().await {
        println!("{}", i);
    }
}

would print

0
1
2
Dropped!

Dependencies

~0.9–1.5MB
~30K SLoC