scanline/
scanline.rs

1// ScanLines is a struct that is used to 'iterate' over a Scanner
2// for each line in a readable source. It cannot (currently) be
3// an actual iterator because of lifetime constraints, because
4// it returns a Scanner that borrows a string from the struct. This
5// however makes it more efficient.
6//
7// This example prints out the first token of each line in this file
8extern crate scanlex;
9use scanlex::ScanLines;
10use std::fs::File;
11
12fn main() {
13    let f = File::open("scanline.rs").expect("cannot open scanline.rs");
14    let mut iter = ScanLines::new(&f);
15    while let Some(s) = iter.next() {
16        let mut s = s.expect("cannot read line");
17        println!("{:?}",s.get());
18    }
19}