File: scanline.rs

package info (click to toggle)
rust-scanlex 0.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144 kB
  • sloc: makefile: 4
file content (19 lines) | stat: -rw-r--r-- 689 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// ScanLines is a struct that is used to 'iterate' over a Scanner
// for each line in a readable source. It cannot (currently) be
// an actual iterator because of lifetime constraints, because
// it returns a Scanner that borrows a string from the struct. This
// however makes it more efficient.
//
// This example prints out the first token of each line in this file
extern crate scanlex;
use scanlex::ScanLines;
use std::fs::File;

fn main() {
    let f = File::open("scanline.rs").expect("cannot open scanline.rs");
    let mut iter = ScanLines::new(&f);
    while let Some(s) = iter.next() {
        let mut s = s.expect("cannot read line");
        println!("{:?}",s.get());
    }
}