[][src]Struct scanner_rust::ScannerStr

pub struct ScannerStr<'a> { /* fields omitted */ }

A simple text scanner which can in-memory-ly parse primitive types and strings using UTF-8 from a string slice.

Implementations

impl<'a> ScannerStr<'a>[src]

pub fn new<S: ?Sized + AsRef<str>>(text: &S) -> ScannerStr[src]

Create a scanner from a string.

extern crate scanner_rust;

use std::io;

use scanner_rust::ScannerStr;

let mut sc = ScannerStr::new("123 456");

impl<'a> ScannerStr<'a>[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::ScannerStr;

let mut sc = ScannerStr::new("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<&'a str>, 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::ScannerStr;

let mut sc = ScannerStr::new("123 456\r\n789 \n\n 中文 ");

assert_eq!(Some("123 456"), sc.next_line().unwrap());
assert_eq!(Some("789 "), sc.next_line().unwrap());
assert_eq!(Some(""), sc.next_line().unwrap());
assert_eq!(Some(" 中文 "), sc.next_line().unwrap());

impl<'a> ScannerStr<'a>[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::ScannerStr;

let mut sc = ScannerStr::new("1 2   c");

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<&'a str>, ScannerError>[src]

Read the next token separated by whitespaces. If there is nothing to read, it will return Ok(None).

extern crate scanner_rust;

use scanner_rust::ScannerStr;

let mut sc = ScannerStr::new("123 456\r\n789 \n\n 中文 ");

assert_eq!(Some("123"), sc.next().unwrap());
assert_eq!(Some("456"), sc.next().unwrap());
assert_eq!(Some("789"), sc.next().unwrap());
assert_eq!(Some("中文"), sc.next().unwrap());
assert_eq!(None, sc.next().unwrap());

impl<'a> ScannerStr<'a>[src]

pub fn next_str(
    &mut self,
    max_number_of_characters: usize
) -> Result<Option<&str>, ScannerError>
[src]

Read the next text (as a string slice) with a specific max number of characters. If there is nothing to read, it will return Ok(None).

extern crate scanner_rust;

use scanner_rust::ScannerStr;

let mut sc = ScannerStr::new("123 456\r\n789 \n\n 中文 ");

assert_eq!(Some("123"), sc.next_str(3).unwrap());
assert_eq!(Some(" 456"), sc.next_str(4).unwrap());
assert_eq!(Some("\r\n789 "), sc.next_str(6).unwrap());
assert_eq!(Some("\n\n 中"), sc.next_str(4).unwrap());
assert_eq!(Some("文"), sc.next().unwrap());
assert_eq!(Some(" "), sc.next_str(2).unwrap());
assert_eq!(None, sc.next_str(2).unwrap());

impl<'a> ScannerStr<'a>[src]

pub fn next_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<&'a str>, ScannerError>
[src]

Read the next text until it reaches a specific boundary. If there is nothing to read, it will return Ok(None).

extern crate scanner_rust;

use scanner_rust::ScannerStr;

let mut sc = ScannerStr::new("123 456\r\n789 \n\n 中文 ");

assert_eq!(Some("123"), sc.next_until(" ").unwrap());
assert_eq!(Some("456\r"), sc.next_until("\n").unwrap());
assert_eq!(Some("78"), sc.next_until("9 ").unwrap());
assert_eq!(Some("\n\n 中文 "), sc.next_until("kk").unwrap());
assert_eq!(None, sc.next().unwrap());

impl<'a> ScannerStr<'a>[src]

pub fn next_u8(&mut self) -> Result<Option<u8>, ScannerError>[src]

Read the next token separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("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 separated 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::ScannerStr;

let mut sc = ScannerStr::new("1 2.5");

assert_eq!(Some(1.0), sc.next_f64().unwrap());
assert_eq!(Some(2.5), sc.next_f64().unwrap());

impl<'a> ScannerStr<'a>[src]

pub fn next_u8_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<u8>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_u8_until(" ").unwrap());
assert_eq!(Some(2), sc.next_u8_until(" ").unwrap());

pub fn next_u16_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<u16>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_u16_until(" ").unwrap());
assert_eq!(Some(2), sc.next_u16_until(" ").unwrap());

pub fn next_u32_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<u32>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_u32_until(" ").unwrap());
assert_eq!(Some(2), sc.next_u32_until(" ").unwrap());

pub fn next_u64_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<u64>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_u64_until(" ").unwrap());
assert_eq!(Some(2), sc.next_u64_until(" ").unwrap());

pub fn next_u128_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<u128>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_u128_until(" ").unwrap());
assert_eq!(Some(2), sc.next_u128_until(" ").unwrap());

pub fn next_usize_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<usize>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_usize_until(" ").unwrap());
assert_eq!(Some(2), sc.next_usize_until(" ").unwrap());

pub fn next_i8_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<i8>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_i8_until(" ").unwrap());
assert_eq!(Some(2), sc.next_i8_until(" ").unwrap());

pub fn next_i16_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<i16>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_i16_until(" ").unwrap());
assert_eq!(Some(2), sc.next_i16_until(" ").unwrap());

pub fn next_i32_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<i32>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_i32_until(" ").unwrap());
assert_eq!(Some(2), sc.next_i32_until(" ").unwrap());

pub fn next_i64_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<i64>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_i64_until(" ").unwrap());
assert_eq!(Some(2), sc.next_i64_until(" ").unwrap());

pub fn next_i128_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<i128>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_i128_until(" ").unwrap());
assert_eq!(Some(2), sc.next_i128_until(" ").unwrap());

pub fn next_isize_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<isize>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2");

assert_eq!(Some(1), sc.next_isize_until(" ").unwrap());
assert_eq!(Some(2), sc.next_isize_until(" ").unwrap());

pub fn next_f32_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<f32>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2.5");

assert_eq!(Some(1.0), sc.next_f32_until(" ").unwrap());
assert_eq!(Some(2.5), sc.next_f32_until(" ").unwrap());

pub fn next_f64_until<S: AsRef<str>>(
    &mut self,
    boundary: S
) -> Result<Option<f64>, ScannerError>
[src]

Read the next text until it reaches a specific boundary 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::ScannerStr;

let mut sc = ScannerStr::new("1 2.5");

assert_eq!(Some(1.0), sc.next_f64_until(" ").unwrap());
assert_eq!(Some(2.5), sc.next_f64_until(" ").unwrap());

Trait Implementations

impl<'a> Debug for ScannerStr<'a>[src]

impl<'a> Iterator for ScannerStr<'a>[src]

type Item = &'a str

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a> RefUnwindSafe for ScannerStr<'a>

impl<'a> Send for ScannerStr<'a>

impl<'a> Sync for ScannerStr<'a>

impl<'a> Unpin for ScannerStr<'a>

impl<'a> UnwindSafe for ScannerStr<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.