Struct scan::Scanner
[−]
[src]
pub struct Scanner<I, F> { /* fields omitted */ }
Scanner is the built-in implementation of the Scan trait. It can be constructed in a few ways.
Examples
Get a scanner of standard input
let scanner = scan::from_stdin();
Get a scanner of a file
let result = scan::from_path("path/to/file.ext"); match result { Ok(scanner) => println!("Got a scanner!"), Err(e) => println!("Could not find/open file"), }
Get a scanner of something implementing Read
let reader = std::fs::File::open(&"path/to/file.ext").unwrap(); let scanner = scan::Scanner::new(reader);
Get a scanner of something implementing Read, with a custom delimiter
let reader = std::fs::File::open(&"path/to/file.ext").unwrap(); fn is_comma(c: &char) -> bool { *c == ',' } let comma_scanner = scan::Scanner::custom(reader, is_comma);
Methods
impl<R: Read, F: Fn(&char) -> bool> Scanner<Chars<R>, F>
[src]
fn custom(reader: R, f: F) -> Scanner<Chars<R>, F>
Creates a custom Scanner, given something that can be read and a function which indicates whether a character is a delimiter.
The function should return true if that character is a delimiter.
Examples
let reader = std::fs::File::open(&"path/to/file.ext").unwrap(); fn is_comma(c: &char) -> bool { *c == ',' } let comma_scanner = scan::Scanner::custom(reader, is_comma);
impl<R: Read> Scanner<Chars<R>, fn(_: &char) -> bool>
[src]
fn new(reader: R) -> Scanner<Chars<R>, fn(_: &char) -> bool>
Creates a scanner of something that can be read. Separates tokens by whitespace.
Examples
use scan::Scan; let reader = std::fs::File::open(&"path/to/file.ext").unwrap(); let mut scanner = scan::Scanner::new(reader); let int = scanner.next::<i32>().unwrap();
Trait Implementations
impl<I: Debug, F: Debug> Debug for Scanner<I, F>
[src]
impl<I, F> Scan for Scanner<I, F> where
I: Iterator<Item = Result<char, CharsError>>,
F: Fn(&char) -> bool,
[src]
I: Iterator<Item = Result<char, CharsError>>,
F: Fn(&char) -> bool,
fn next_str(&mut self) -> Option<Result<String, CharsError>>
Extract the next string. There are three possible results: * A valid String
, as Some(Ok(String))
* An indication that there are no more strings, as None
* An indication that some error occured and new characters could not be produced, as Some(Err(Error))
The choice to return an Option<Result>
instead of the other way around was made to mirror the convention of the io::Chars
struct. Read more
fn next<F: FromStr>(&mut self) -> Result<F, ScanError<F>>
Parse the next string in the scanner as an F: FromStr
.