#codec #async #await

nightly futures_codec

Utilities for encoding and decoding frames using async/await

7 releases

✓ Uses Rust 2018 edition

0.2.3 Jul 10, 2019
0.2.2 May 4, 2019
0.2.1 Apr 26, 2019
0.1.2 Apr 26, 2019

#145 in Asynchronous

Download history 60/week @ 2019-04-24 25/week @ 2019-05-01 3/week @ 2019-05-08 43/week @ 2019-05-15 25/week @ 2019-05-22 16/week @ 2019-05-29 15/week @ 2019-06-05 67/week @ 2019-06-12 125/week @ 2019-06-19 142/week @ 2019-06-26 68/week @ 2019-07-03

198 downloads per month
Used in 2 crates

MIT license

19KB
422 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.

# #![feature(async_await, await_macro)]
# use futures::{executor, SinkExt, TryStreamExt};
# use std::io::Cursor;
use futures_codec::{LinesCodec, Framed};

async move {
    # let mut buf = vec![];
    # let stream = Cursor::new(&mut buf);
    // let stream = ...
    let mut framed = Framed::new(stream, LinesCodec {});

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

Dependencies

~1MB
~24K SLoC