Crates.io | async-utf8-decoder |
lib.rs | async-utf8-decoder |
version | 1.0.0 |
source | src |
created_at | 2021-03-09 08:54:49.846062 |
updated_at | 2024-11-08 03:00:16.577918 |
description | Convert AsyncRead to incremental UTF8 string stream |
homepage | |
repository | https://github.com/lambdalisue/rs-async-utf8-decoder |
max_upload_size | |
id | 366200 |
size | 41,561 |
async-utf8-decoder
crate provides Utf8Decoder
which allows to convert any object which
implements AsyncRead
trait into a string stream which implements Stream
trait.
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());
The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.