4 releases (stable)

Uses new Rust 2024

2.0.0 Jan 28, 2026
1.0.1 Jul 21, 2019
1.0.0 Jul 19, 2019
0.1.0 Jul 19, 2019

#173 in Parser implementations

Download history 69084/week @ 2026-01-23 77448/week @ 2026-01-30 98201/week @ 2026-02-06 71566/week @ 2026-02-13 75123/week @ 2026-02-20 82185/week @ 2026-02-27 112512/week @ 2026-03-06 173791/week @ 2026-03-13 144483/week @ 2026-03-20 134820/week @ 2026-03-27 146301/week @ 2026-04-03 149242/week @ 2026-04-10 133863/week @ 2026-04-17 142273/week @ 2026-04-24 149678/week @ 2026-05-01 107908/week @ 2026-05-08

560,388 downloads per month
Used in 254 crates (10 directly)

MIT/Apache

15KB
221 lines

UTF-8 decode

CI Crate informations License Documentation

This crates provides incremental UTF-8 decoders implementing the Iterator trait, wrapping around u8 bytes iterators.

It also provide the const-compatible try_decode_char to decode UTF-8 byte streams, even in const contexts.

Decoder

The Decoder iterator can be used, for instance, to decode u8 slices.

use utf8_decode::Decoder;
let bytes = [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33];

let decoder = Decoder::new(bytes.iter().cloned());

let mut string = String::new();
for c in decoder {
    string.push(c?);
}

println!("{}", string);

TryDecoder

The TryDecoder iterator can be used, for instance, to decode UTF-8 encoded files.

use utf8_decode::TryDecoder;
let file = File::open("examples/file.txt")?;

let decoder = TryDecoder::new(file.bytes());

let mut string = String::new();
for c in decoder {
    string.push(c?);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Features