tokio-into-sink

Crates.iotokio-into-sink
lib.rstokio-into-sink
version0.1.0
sourcesrc
created_at2023-09-15 13:36:01.336802
updated_at2023-09-15 13:36:01.336802
descriptionconvert a tokio::io::AsyncWrite into a futures::Sink for bytes
homepage
repositoryhttps://github.com/aatifsyed/tokio-into-sink
max_upload_size
id973673
size6,846
Aatif Syed (aatifsyed)

documentation

https://docs.rs/tokio-into-sink

README

Use an [AsyncWrite] as a [Sink]<Item: AsRef<[u8]>.

This adapter produces a sink that will write each value passed to it into the underlying writer. Note that this function consumes the given writer, returning a wrapped version.

use tokio_into_sink::IntoSinkExt as _;
use futures::{stream, StreamExt as _};
use std::io;

let stream = stream::iter(["hello", "world"]).map(io::Result::Ok);
let write = tokio::fs::File::create("/dev/null").await.unwrap();
let sink = write.into_sink();
stream.forward(sink).await.unwrap();

Ported from futures::io::AsyncWriteExt::into_sink.

Commit count: 6

cargo fmt