[][src]Function rut::parse

Important traits for Parse<'_>
pub fn parse<'a>(bytes: &'a [u8]) -> Parse<'a>

Creates an iterator for parsing UTF-8 sequences from a byte slice.

Examples

// Valid UTF-8 encoding of '€'
let bytes = [0xE2, 0x82, 0xAC];
 
let mut it = rut::parse(&bytes);
 
assert_eq!(it.next(), Some(Ok('€')));
assert_eq!(it.next(), None);
use rut::Utf8ParseError::*;
 
// Ill-formed sequence followed by 2 valid characters
let bytes = [0xC2, 0x41, 0x42];
 
let mut it = rut::parse(&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);