#utf-8 #stream #async #decoder #async-read #incremental #io

async-utf8-decoder

将 AsyncRead 转换为增量 UTF-8 字符串流

10 个版本

0.3.3 2023年6月2日
0.3.2 2022年2月14日
0.3.1 2021年9月16日
0.3.0 2021年7月1日
0.1.1 2021年3月9日

#383 in 异步

Download history 139/week @ 2024-03-13 181/week @ 2024-03-20 143/week @ 2024-03-27 160/week @ 2024-04-03 239/week @ 2024-04-10 46/week @ 2024-04-17 42/week @ 2024-04-24 77/week @ 2024-05-01 80/week @ 2024-05-08 59/week @ 2024-05-15 39/week @ 2024-05-22 34/week @ 2024-05-29 60/week @ 2024-06-05 62/week @ 2024-06-12 43/week @ 2024-06-19 44/week @ 2024-06-26

213 个月下载量
用于 5 个 Crates (2 个直接使用)

MIT 许可证

21KB
298 代码行

crates.io dependency status docs.rs MIT License Build Test Audit codecov

async-utf8-decoder

异步和增量 UTF-8 解码器

async-utf8-decoder 包提供 Utf8Decoder,允许将实现 AsyncRead 特性的任何对象转换为实现 Stream 特性的字符串流。

示例

use futures::io;
use futures::channel::mpsc;
use async_utf8_decoder::Utf8Decoder;

let (mut tx, rx) = mpsc::unbounded::<io::Result<Vec<u8>>>();
let mut decoder = Utf8Decoder::new(rx.into_async_read());

tx.send(Ok(vec![240])).await?;
assert!(timeout(decoder.next()).await.is_err());
tx.send(Ok(vec![159])).await?;
assert!(timeout(decoder.next()).await.is_err());
tx.send(Ok(vec![146])).await?;
assert!(timeout(decoder.next()).await.is_err());
tx.send(Ok(vec![150])).await?;
assert_eq!("💖", timeout(decoder.next()).await?.unwrap()?);
assert!(timeout(decoder.next()).await.is_err());

许可证

代码遵循 MIT 许可证,可在 LICENSE 文件中找到。贡献者需要同意在此存储库中发送的任何修改都遵循许可证。

依赖

~0.4–0.9MB
~19K SLoC