#codec #future #async #async-io

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

#931 in Asynchronous

Download history 9258/week @ 2024-07-21 7763/week @ 2024-07-28 10482/week @ 2024-08-04 16622/week @ 2024-08-11 10348/week @ 2024-08-18 11500/week @ 2024-08-25 13216/week @ 2024-09-01 9949/week @ 2024-09-08 6014/week @ 2024-09-15 8086/week @ 2024-09-22 9776/week @ 2024-09-29 10992/week @ 2024-10-06 11569/week @ 2024-10-13 9050/week @ 2024-10-20 11040/week @ 2024-10-27 11035/week @ 2024-11-03

43,096 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.3–3MB
~65K SLoC