[−][src]Trait streams_rs::Stream
Suppose you need to process each line of a text file. One way to do this is to read the file in as a single large string and use something
like split
to turn it into a list. This works when the file is small, but because the entire file is loaded into memory, it does not
scale well when the file is large.
More commonly, the read_line function can be used to read one line at a time from a channel. This typically looks like:
// LineReadStream is just example, you can implement your own stream for reading files. use streams_rs::*; use io_stream::*; let mut c = std::io::Cursor::new(b"a\n b\n c"); let mut stream = LineReadStream::new(&mut c); let _ = smatch!(match (stream) { [a=> b=> c =>] => { println!("{:?} {:?} {:?}",a,b,c); } });
Associated Types
type Item
Required methods
fn token(&mut self, x: usize) -> StreamResult<Self::Item>
Returns token at x
. It's possible to cache values. FnStream for example caches all tokens returned from getter.
fn junk(&mut self, x: usize)
Basucally same as truncating vector.
fn pos(&self) -> usize
Return stream position, does not used by macro or streams-rs, but might be usefull for someone.