[−][src]Struct scanner_rust::Scanner
A simple text scanner which can parse primitive types and strings using UTF-8.
Methods
impl<R: Read> Scanner<R>
[src]
pub fn with_capacity(reader: R, capacity: usize) -> Scanner<R>
[src]
Create a scanner with a specific capacity.
extern crate scanner_rust; use std::io; use scanner_rust::Scanner; let mut sc = Scanner::with_capacity(io::stdin(), 1024);
pub fn new(reader: R) -> Scanner<R>
[src]
Create a scanner with a default capacity.
extern crate scanner_rust; use std::io; use scanner_rust::Scanner; let mut sc = Scanner::new(io::stdin());
impl<R: Read> Scanner<R>
[src]
pub fn scan_stream(reader: R) -> Scanner<R>
[src]
Create a scanner to read data from a reader.
extern crate scanner_rust; use std::io; use scanner_rust::Scanner; let mut sc = Scanner::scan_stream(io::stdin());
impl Scanner<File>
[src]
pub fn scan_file(file: File) -> Result<Scanner<File>, ScannerError>
[src]
Create a scanner to read data from a file.
extern crate scanner_rust; use std::fs::File; use scanner_rust::Scanner; let mut sc = Scanner::scan_file(File::open("Cargo.toml").unwrap()).unwrap();
pub fn scan_path<P: AsRef<Path>>(path: P) -> Result<Scanner<File>, ScannerError>
[src]
Create a scanner to read data from a file by its path.
extern crate scanner_rust; use std::fs::File; use scanner_rust::Scanner; let mut sc = Scanner::scan_path("Cargo.toml").unwrap();
impl Scanner<Cursor<String>>
[src]
pub fn scan_string<S: Into<String>>(s: S) -> Scanner<Cursor<String>>
[src]
Create a scanner to read data from a string.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_string(String::from("5 12 2.4 c 中文也行"));
impl<'_> Scanner<&'_ [u8]>
[src]
pub fn scan_slice<B: AsRef<[u8]> + ?Sized>(b: &B) -> Scanner<&[u8]>
[src]
Create a scanner to read data from a u8
slice.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("5 12 2.4 c 中文也行");
impl Scanner<Cursor<Vec<u8>>>
[src]
pub fn scan_vec(v: Vec<u8>) -> Scanner<Cursor<Vec<u8>>>
[src]
Create a scanner to read data from a Vec
instance which contains UTF-8 data.
extern crate scanner_rust; use scanner_rust::Scanner; let v = String::from("5 12 2.4 c 中文也行").into_bytes(); let mut sc = Scanner::scan_vec(v);
impl<R: Read> Scanner<R>
[src]
pub fn get_remains(&self) -> &[u8]
[src]
Get the data remaining in the buffer.
impl<R: Read> Scanner<R>
[src]
pub fn next_char(&mut self) -> Result<Option<char>, ScannerError>
[src]
Read the next char. If the data is not a correct char, it will return a Ok(Some(REPLACEMENT_CHARACTER))
which is �. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("5 c 中文"); assert_eq!(Some('5'), sc.next_char().unwrap()); assert_eq!(Some(' '), sc.next_char().unwrap()); assert_eq!(Some('c'), sc.next_char().unwrap()); assert_eq!(Some(' '), sc.next_char().unwrap()); assert_eq!(Some('中'), sc.next_char().unwrap()); assert_eq!(Some('文'), sc.next_char().unwrap()); assert_eq!(None, sc.next_char().unwrap());
pub fn next_line(&mut self) -> Result<Option<String>, ScannerError>
[src]
Read the next line but not include the tailing line character (or line chracters like CrLf
(\r\n
)). If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("123 456\r\n789 \n\n 中文 "); assert_eq!(Some("123 456".into()), sc.next_line().unwrap()); assert_eq!(Some("789 ".into()), sc.next_line().unwrap()); assert_eq!(Some("".into()), sc.next_line().unwrap()); assert_eq!(Some(" 中文 ".into()), sc.next_line().unwrap());
impl<R: Read> Scanner<R>
[src]
pub fn skip_whitespaces(&mut self) -> Result<bool, ScannerError>
[src]
Skip the next whitespaces (javaWhitespace
). If there is nothing to read, it will return Ok(false)
.
extern crate scanner_rust; use scanner_rust::Scanner; let v = String::from("1 2 c").into_bytes(); let mut sc = Scanner::scan_vec(v); assert_eq!(Some('1'), sc.next_char().unwrap()); assert_eq!(Some(' '), sc.next_char().unwrap()); assert_eq!(Some('2'), sc.next_char().unwrap()); assert_eq!(true, sc.skip_whitespaces().unwrap()); assert_eq!(Some('c'), sc.next_char().unwrap()); assert_eq!(false, sc.skip_whitespaces().unwrap());
pub fn next(&mut self) -> Result<Option<String>, ScannerError>
[src]
Read the next token seperated by whitespaces. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("123 456\r\n789 \n\n 中文 "); assert_eq!(Some("123".into()), sc.next().unwrap()); assert_eq!(Some("456".into()), sc.next().unwrap()); assert_eq!(Some("789".into()), sc.next().unwrap()); assert_eq!(Some("中文".into()), sc.next().unwrap()); assert_eq!(None, sc.next().unwrap());
pub fn next_u8(&mut self) -> Result<Option<u8>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a u8
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_u8().unwrap()); assert_eq!(Some(2), sc.next_u8().unwrap());
pub fn next_u16(&mut self) -> Result<Option<u16>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a u16
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_u16().unwrap()); assert_eq!(Some(2), sc.next_u16().unwrap());
pub fn next_u32(&mut self) -> Result<Option<u32>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a u32
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_u32().unwrap()); assert_eq!(Some(2), sc.next_u32().unwrap());
pub fn next_u64(&mut self) -> Result<Option<u64>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a u64
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_u64().unwrap()); assert_eq!(Some(2), sc.next_u64().unwrap());
pub fn next_u128(&mut self) -> Result<Option<u128>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a u128
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_u128().unwrap()); assert_eq!(Some(2), sc.next_u128().unwrap());
pub fn next_usize(&mut self) -> Result<Option<usize>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a usize
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_usize().unwrap()); assert_eq!(Some(2), sc.next_usize().unwrap());
pub fn next_i8(&mut self) -> Result<Option<i8>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a i8
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_i8().unwrap()); assert_eq!(Some(2), sc.next_i8().unwrap());
pub fn next_i16(&mut self) -> Result<Option<i16>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a i16
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_i16().unwrap()); assert_eq!(Some(2), sc.next_i16().unwrap());
pub fn next_i32(&mut self) -> Result<Option<i32>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a i32
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_i32().unwrap()); assert_eq!(Some(2), sc.next_i32().unwrap());
pub fn next_i64(&mut self) -> Result<Option<i64>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a i64
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_i64().unwrap()); assert_eq!(Some(2), sc.next_i64().unwrap());
pub fn next_i128(&mut self) -> Result<Option<i128>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a i128
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_i128().unwrap()); assert_eq!(Some(2), sc.next_i128().unwrap());
pub fn next_isize(&mut self) -> Result<Option<isize>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a isize
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2"); assert_eq!(Some(1), sc.next_isize().unwrap()); assert_eq!(Some(2), sc.next_isize().unwrap());
pub fn next_f32(&mut self) -> Result<Option<f32>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a f32
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2.5"); assert_eq!(Some(1.0), sc.next_f32().unwrap()); assert_eq!(Some(2.5), sc.next_f32().unwrap());
pub fn next_f64(&mut self) -> Result<Option<f64>, ScannerError>
[src]
Read the next token seperated by whitespaces and parse it to a f64
value. If there is nothing to read, it will return Ok(None)
.
extern crate scanner_rust; use scanner_rust::Scanner; let mut sc = Scanner::scan_slice("1 2.5"); assert_eq!(Some(1.0), sc.next_f64().unwrap()); assert_eq!(Some(2.5), sc.next_f64().unwrap());
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,