#future #sink #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

#1609 in Asynchronous

Download history 18709/week @ 2024-07-24 17676/week @ 2024-07-31 20960/week @ 2024-08-07 19070/week @ 2024-08-14 14733/week @ 2024-08-21 13995/week @ 2024-08-28 14380/week @ 2024-09-04 11691/week @ 2024-09-11 10712/week @ 2024-09-18 12467/week @ 2024-09-25 12330/week @ 2024-10-02 10322/week @ 2024-10-09 8781/week @ 2024-10-16 8404/week @ 2024-10-23 7920/week @ 2024-10-30 7051/week @ 2024-11-06

33,780 downloads per month
Used in 111 crates (10 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

~105KB