#sink #future #async

quicksink

Create a Sink from some value and a closure returning a Future

3 releases

0.1.2 Apr 7, 2020
0.1.1 Jan 7, 2020
0.1.0 Dec 10, 2019

#1273 in Asynchronous

Download history 33259/week @ 2024-03-05 34487/week @ 2024-03-12 40452/week @ 2024-03-19 35189/week @ 2024-03-26 48078/week @ 2024-04-02 48466/week @ 2024-04-09 38599/week @ 2024-04-16 38851/week @ 2024-04-23 31420/week @ 2024-04-30 27903/week @ 2024-05-07 33250/week @ 2024-05-14 38719/week @ 2024-05-21 42203/week @ 2024-05-28 33796/week @ 2024-06-04 35047/week @ 2024-06-11 23320/week @ 2024-06-18

144,645 downloads per month
Used in 212 crates (9 directly)

Apache-2.0 OR MIT

15KB
260 lines

QuickSink

Allows creating an implementation of the Sink trait from an initial value and a closure returning a Future.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Create a Sink implementation from an initial value and a closure returning a Future.

This is very similar to how futures::stream::unfold creates a Stream implementation from a seed value and a future-returning closure.

Examples

use async_std::io;
use futures::prelude::*;
use quicksink::Action;

quicksink::make_sink(io::stdout(), |mut stdout, action| async move {
    match action {
        Action::Send(x) => stdout.write_all(x).await?,
        Action::Flush => stdout.flush().await?,
        Action::Close => stdout.close().await?
    }
    Ok::<_, io::Error>(stdout)
});

Panics

  • If any of the Sink methods produce an error, the sink transitions to a failure state and none of its methods must be called afterwards or else a panic will occur.
  • If Sink::poll_close has been called, no other sink method must be called afterwards or else a panic will be caused.

Dependencies

~98KB