#codec #future #async

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

#790 in Asynchronous

Download history 3981/week @ 2023-12-04 3662/week @ 2023-12-11 4967/week @ 2023-12-18 3313/week @ 2023-12-25 4013/week @ 2024-01-01 5296/week @ 2024-01-08 4929/week @ 2024-01-15 5338/week @ 2024-01-22 5007/week @ 2024-01-29 6065/week @ 2024-02-05 5948/week @ 2024-02-12 6479/week @ 2024-02-19 6019/week @ 2024-02-26 6400/week @ 2024-03-04 5477/week @ 2024-03-11 6328/week @ 2024-03-18

24,608 downloads per month
Used in fewer than 14 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
~62K SLoC