#future #futures #async #codec

futures_codec

Utilities for encoding and decoding frames using async/await

10 releases

✓ Uses Rust 2018 edition

0.3.0 Sep 24, 2019
0.2.5 Jul 22, 2019
0.2.2 May 4, 2019
0.2.1 Apr 26, 2019
0.1.2 Apr 26, 2019

#42 in Asynchronous

Download history 47/week @ 2019-06-11 145/week @ 2019-06-18 148/week @ 2019-06-25 67/week @ 2019-07-02 103/week @ 2019-07-09 224/week @ 2019-07-16 130/week @ 2019-07-23 280/week @ 2019-07-30 221/week @ 2019-08-06 171/week @ 2019-08-13 2749/week @ 2019-08-20 1392/week @ 2019-08-27 747/week @ 2019-09-03 578/week @ 2019-09-10 341/week @ 2019-09-17

2,408 downloads per month
Used in 8 crates

MIT license

23KB
449 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)]
# 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
~22K SLoC