#codec #future #async #frame #byte #framed #decoding

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

#961 in Asynchronous

Download history 5431/week @ 2024-03-14 6632/week @ 2024-03-21 6836/week @ 2024-03-28 5983/week @ 2024-04-04 5825/week @ 2024-04-11 5379/week @ 2024-04-18 5075/week @ 2024-04-25 5725/week @ 2024-05-02 6425/week @ 2024-05-09 4849/week @ 2024-05-16 4823/week @ 2024-05-23 5092/week @ 2024-05-30 5337/week @ 2024-06-06 5814/week @ 2024-06-13 7628/week @ 2024-06-20 6052/week @ 2024-06-27

25,855 downloads per month
Used in fewer than 15 crates

MIT license

42KB
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.

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);
}

Dependencies

~2.2–3MB
~64K SLoC