Function encode_unicode::iter_units[][src]

pub fn iter_units<U: Borrow<Utf16Char>, I: IntoIterator<Item = U>>(
    iterable: I
) -> Utf16CharSplitter<U, I::IntoIter>

Notable traits for Utf16CharSplitter<U, I>

impl<U: Borrow<Utf16Char>, I: Iterator<Item = U>> Iterator for Utf16CharSplitter<U, I> type Item = u16;

Converts an iterator of Utf16Char (or &Utf16Char) to an iterator of u16s.
Is equivalent to calling .flat_map() on the original iterator, but the returned iterator is about twice as fast.

The exact number of units cannot be known in advance, but size_hint() gives the possible range.

Examples

From iterator of values:

use encode_unicode::{iter_units, CharExt};

let iterator = "foo".chars().map(|c| c.to_utf16() );
let mut units = [0; 4];
for (u,dst) in iter_units(iterator).zip(&mut units) {*dst=u;}
assert_eq!(units, ['f' as u16, 'o' as u16, 'o' as u16, 0]);

From iterator of references:

use encode_unicode::{iter_units, CharExt, Utf16Char};

// (💣 takes two units)
let chars: Vec<Utf16Char> = "💣 bomb 💣".chars().map(|c| c.to_utf16() ).collect();
let units: Vec<u16> = iter_units(&chars).collect();
let flat_map: Vec<u16> = chars.iter().flat_map(|u16c| *u16c ).collect();
assert_eq!(units, flat_map);