Trait split_by::SplitBy [] [src]

pub trait SplitBy<'a, R: Read> {
    fn split_by<A: Automaton<&'a [u8]>>(
        self,
        searcher: &'a A
    ) -> SplitByIter<'a, R, A>
    where
        Self: Read
; }

Allows spliting any Read stream by arbitrary number of byte sequences

Examples

extern crate split_by;
 
use split_by::{SplitBy, AcAutomaton};
 
let ac = AcAutomaton::new(vec!["--------".as_bytes(), "********".as_bytes(), "########".as_bytes()]);
let mut splits = br#"first
--------
second
********########
third
################
last"#.split_by(&ac);

assert!(splits.next().unwrap().unwrap().as_slice() == b"first\n");
assert!(splits.next().unwrap().unwrap().as_slice() == b"\nsecond\n");
assert!(splits.next().unwrap().unwrap().as_slice() == b"\nthird\n");
assert!(splits.next().unwrap().unwrap().as_slice() == b"\nlast");
assert!(splits.next().is_none());

The iterator never produces empty vec, even if the input begins or ends with the splitter or if there are consecutive splitters present

Required Methods

Important traits for SplitByIter<'a, R, A>

Implementors