Skip to main content

Crate utf8_decode

Crate utf8_decode 

Source
Expand description

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?);
}

Structs§

Decoder
UTF-8 decoder iterator.
TryDecoder
UTF-8 decoder iterator, with fallible source.
Utf8Error

Functions§

try_decode_char
Read the UTF-8 encoded character out of the given slice at position i.
try_decode_iter_char
Read the next Unicode character out of the given fallible byte iterator.