buf_read_splitter
A stream reader with ability to read a stream until a defined pattern is reached (usually an array of [u8])
This could be a simple separator :
use Read;
use ;
// To simulate a stream of this content :
let input = "First<SEP>Second<SEP>Third<SEP>Fourth<SEP>Fifth".to_string;
let mut input_reader = input.as_bytes;
// Create a reader that will end at each "<SEP>" :
let mut reader = new;
// List of separate String will be listed in a Vector :
let mut words = Vecnew;
// Working variables :
let mut word = Stringnew;
let mut buf = vec!;
while
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
For more complexe pattern, the trait Matcher has to be implementing.
For example above a Matcher able to split a stream at each Mac, Unix or Windows end of line :
use ;
...so the reader can be created like with this code :
let mut reader = new;
The separator pattern can be changed on the fly by calling "matcher" function :
reader.matcher
The buffer part can be limited in size readed.
For example to limit to 100 bytes :
reader.set_limit_read;
...and to reinitialize it to "no limit" :
reader.set_limit_read;
A call to ".next_part()" pass to the next part, however the end was reached or not (skips what has not been readed)\
For debug purpose, you can activate the "log" features in the Cargo.toml (slow down processing) :
buf_read_splitter =
License: MIT