#stream #io-stream #buffer #io

bytes-stream

用于处理字节流的小工具函数

3 个版本

0.0.3 2023年5月14日
0.0.2 2023年4月1日
0.0.1 2023年4月1日

#893 in 异步

Download history · Rust 包仓库 28/week @ 2024-03-09 · Rust 包仓库 57/week @ 2024-03-16 · Rust 包仓库 86/week @ 2024-03-23 · Rust 包仓库 70/week @ 2024-03-30 · Rust 包仓库 33/week @ 2024-04-06 · Rust 包仓库 24/week @ 2024-04-13 · Rust 包仓库 32/week @ 2024-04-20 · Rust 包仓库 90/week @ 2024-04-27 · Rust 包仓库 1/week @ 2024-05-04 · Rust 包仓库 10/week @ 2024-05-11 · Rust 包仓库 9/week @ 2024-05-18 · Rust 包仓库 6/week @ 2024-05-25 · Rust 包仓库 7/week @ 2024-06-01 · Rust 包仓库 17/week @ 2024-06-08 · Rust 包仓库 27/week @ 2024-06-15 · Rust 包仓库 6/week @ 2024-06-22 · Rust 包仓库

58 每月下载量

MIT 许可证

21KB
385

bytes-stream

用于与 Streams 中的 Bytes 进行交互的小工具函数。

示例

将字节流分割成块

use bytes::Bytes;
use bytes_stream::BytesStream;
use futures::StreamExt;

fn main() {
    futures::executor::block_on(async {
        let stream = futures::stream::iter(vec![
            Bytes::from_static(&[1, 2, 3]),
            Bytes::from_static(&[4, 5, 6]),
            Bytes::from_static(&[7, 8, 9]),
        ]);

        let mut stream = stream.bytes_chunks(4);

        assert_eq!(stream.next().await, Some(Bytes::from_static(&[1, 2, 3, 4])));
        assert_eq!(stream.next().await, Some(Bytes::from_static(&[5, 6, 7, 8])));
        assert_eq!(stream.next().await, Some(Bytes::from_static(&[9])));
        assert_eq!(stream.next().await, None);
    });
}

依赖

~240KB