[][src]Function rut::decode

Important traits for Decode<'_>
pub fn decode(bytes: &[u8]) -> Decode

Creates an iterator for decoding characters from a byte slice.

This is done by calling decode_one repeatedly until the slice has been exhausted.

Examples

// Valid UTF-8 encoding of '€'
let bytes = [0xE2, 0x82, 0xAC];

let mut it = rut::decode(&bytes);

assert_eq!(it.next(), Some(Ok('€')));
assert_eq!(it.next(), None);
use rut::Error::*;

// Ill-formed sequence followed by 2 valid characters
let bytes = [0xC2, 0x41, 0x42];

let mut it = rut::decode(&bytes);

assert_eq!(it.next(), Some(Err(BrokenSequence)));
assert_eq!(it.next(), Some(Ok('A')));
assert_eq!(it.next(), Some(Ok('B')));
assert_eq!(it.next(), None);