Hello,
I wrote a lib that split a stream reader (called buf_read_splitter)
The basic usage needs too much lines of code for a so simple purpose. For example, to count parts separates by "<SEP>" and total number of characters (excluding separators size) :
/*** Declarations ***/
let mut stream = ....
let separator = "<SEP>";
let mut reader = BufReadSplitter::new(
&mut stream,
SimpleMatcher::new(separator.as_bytes()),
Options::default(),
);
let mut buf = vec![0u8; buf_size];
let mut nb_part_found = 0usize;
let mut nb_chars = 0usize;
/*** Loop ***/
while {
let sz = reader.read(&mut buf).unwrap();
if sz > 0 {
nb_chars += sz;
true
} else {
nb_part_found += 1;
match reader.next_part().unwrap() {
//Pass to the next part of the buffer
Some(_) => true, //There's a next part
None => false, //End of the stream
}
}
} {}
I'd like to offer the possibility of an iterator, for example this code below :
...
/*** Loop ***/
for part in reader.iter() {
let sz = part.read(&mut buf).unwrap();
if sz > 0 {
nb_chars += sz;
true
} else {
nb_part_found += 1;
}
}
I don't find any solution because of the borrow checker between the stream owns by reader and (so) can't be own by part.
Do you have any idea of how to do something like that ?