Merge

Trait Merge 

Source
pub trait Merge<'t>: Iterator<Item = &'t str> + Sized {
    // Provided methods
    fn merge_all(self, parent: &'t str) -> Option<&'t str> { ... }
    fn merge_by<F: FnMut(&str, &str) -> bool>(
        self,
        parent: &'t str,
        f: F,
    ) -> MergeIter<'t, Self, F>  { ... }
}
Expand description

Iterators for merging substrings.

The parent string is needed for satefy.

Provided Methods§

Source

fn merge_all(self, parent: &'t str) -> Option<&'t str>

Merge an iterator of adjacent &strs in parent into a single &str

Returns None if some &strs are not adjacent

Source

fn merge_by<F: FnMut(&str, &str) -> bool>( self, parent: &'t str, f: F, ) -> MergeIter<'t, Self, F>

Merge adjacent pairs of &str’s in parent by a predicate,

Function f only gets called on adjacent substrings.

§Example

Merging all adjacent substrings:

let string = "foobarbaz quxquux";
let substrs = [&string[0..3], &string[3..6], &string[6..9], 
    &string[10..13], &string[13..17]];
let mut iter = substrs.into_iter().merge_by(string, |_, _| true);
assert_eq!(iter.next(), Some("foobarbaz"));
assert_eq!(iter.next(), Some("quxquux"));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'t, T> Merge<'t> for T
where T: Iterator<Item = &'t str>,