Trait odds::slice::SliceIterExt [] [src]

pub trait SliceIterExt: Iterator {
    fn mend_slices(self) -> MendSlices<Self>
    where
        Self: Sized,
        Self::Item: MendSlice
, { ... } }

Extra iterator adaptors for iterators of slice elements.

Provided Methods

Return an iterator adaptor that joins together adjacent slices if possible.

Only implemented for iterators with slice or string slice elements. Only slices that are contiguous together can be joined.

use odds::slice::SliceIterExt;

// Split a string into a slice per letter, filter out whitespace,
// and join into words again by mending adjacent slices.
let text = String::from("Warning:  γ-radiation (ionizing)");
let char_slices = text.char_indices()
                      .map(|(index, ch)| &text[index..index + ch.len_utf8()]);
let words = char_slices.filter(|s| !s.chars().any(char::is_whitespace))
                       .mend_slices();

assert!(words.eq(vec!["Warning:", "γ-radiation", "(ionizing)"]));

Implementors