#future #futures #async #codec

futures_codec

Utilities for encoding and decoding frames using async/await

13 releases

✓ Uses Rust 2018 edition

0.3.3 Nov 29, 2019
0.3.2 Nov 29, 2019
0.3.0 Sep 24, 2019
0.2.5 Jul 22, 2019
0.1.2 Apr 26, 2019

#32 in Asynchronous

Download history 238/week @ 2019-08-16 3381/week @ 2019-08-23 902/week @ 2019-08-30 761/week @ 2019-09-06 407/week @ 2019-09-13 630/week @ 2019-09-20 1148/week @ 2019-09-27 557/week @ 2019-10-04 800/week @ 2019-10-11 561/week @ 2019-10-18 659/week @ 2019-10-25 882/week @ 2019-11-01 1052/week @ 2019-11-08 995/week @ 2019-11-15 1503/week @ 2019-11-22

3,524 downloads per month
Used in 8 crates

MIT license

25KB
546 lines

futures_codec

Utilities for encoding and decoding frames using async/await.

Contains adapters to go from streams of bytes, AsyncRead and AsyncWrite, to framed streams implementing Sink and Stream. Framed streams are also known as transports.

Docs | Crate

use futures_codec::{LinesCodec, Framed};

async fn main() {
    // let stream = ...
    let mut framed = Framed::new(stream, LinesCodec {});

    while let Some(line) = framed.try_next().await.unwrap() {
        println!("{:?}", line);
    }
}

lib.rs:

Utilities for encoding and decoding frames using async/await.

Contains adapters to go from streams of bytes, AsyncRead and AsyncWrite, to framed streams implementing Sink and Stream. Framed streams are also known as transports.

# futures::executor::block_on(async move {
use futures::TryStreamExt;
use futures::io::Cursor;
use futures_codec::{LinesCodec, Framed};

let io = Cursor::new(Vec::new());
let mut framed = Framed::new(io, LinesCodec);

while let Some(line) = framed.try_next().await? {
    dbg!(line);
}
# Ok::<_, std::io::Error>(())
# }).unwrap();

Dependencies

~2MB
~42K SLoC