#future #futures #async #codec

futures_codec

Utilities for encoding and decoding frames using async/await

16 unstable releases (3 breaking)

0.4.1 Jun 21, 2020
0.4.0 Jan 26, 2020
0.3.4 Dec 14, 2019
0.3.3 Nov 29, 2019
0.2.5 Jul 22, 2019

#22 in Asynchronous

Download history 8305/week @ 2020-04-21 6665/week @ 2020-04-28 8139/week @ 2020-05-05 11027/week @ 2020-05-12 8656/week @ 2020-05-19 8474/week @ 2020-05-26 8493/week @ 2020-06-02 9045/week @ 2020-06-09 10104/week @ 2020-06-16 10501/week @ 2020-06-23 13608/week @ 2020-06-30 12594/week @ 2020-07-07 11572/week @ 2020-07-14 12223/week @ 2020-07-21 12245/week @ 2020-07-28 11037/week @ 2020-08-04

32,590 downloads per month
Used in 45 crates (19 directly)

MIT license

41KB
872 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.

Latest Version Rust Documentation Build Status LICENSE

Example

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

~1.3–2MB
~42K SLoC