channel_io

Crates.iochannel_io
lib.rschannel_io
version0.1.3
sourcesrc
created_at2021-10-15 21:41:46.754855
updated_at2021-10-15 23:43:06.131053
descriptionReader implementation on channel of bytes
homepagehttps://github.com/sstadick/channel_io
repositoryhttps://github.com/sstadick/channel_io
max_upload_size
id465646
size13,321
Seth (sstadick)

documentation

https://docs.rs/channel_io

README

📖 channel_io

Build Status license Version info

A small helper library to convert a flume channel of Bytes into a Channel{Reader,Writer} that implements {Read,Write}.

Example

use std::io::Read;

use bytes::Bytes;
use channel_reader::ChannelReader;
use flume::bounded;

fn main() {
    let (tx, rx) = bounded(10);
    let sender_thread = std::thread::spawn(move || {
        for i in 0..10 {
            let buffer = Bytes::from(vec![i; 10]);
            tx.send(buffer).unwrap();
        }
    });
    sender_thread.join().unwrap();

    let mut reader = ChannelReader::new(rx);
    let mut buffer = vec![];
    reader.read_to_end(&mut buffer).unwrap();
    assert_eq!(buffer.len(), 100);
}

Why flume?

The goal is to bridge an async reader-like-thing (in this case a DmaStreamReader in Glommio) into a synchronous reader.

Why bytes?

I like the API, and in theory as chunks are dropped on the sync side of the sender depending on how the caller is doing things the memory can be reused.

Commit count: 15

cargo fmt