Skip to main content

Scanner

Struct Scanner 

Source
pub struct Scanner<R: Read, const N: usize = 256> { /* private fields */ }
Expand description

A simple text scanner which can parse primitive types and strings using UTF-8.

Implementations§

Source§

impl<R: Read> Scanner<R>

Source

pub fn new(reader: R) -> Scanner<R>

Create a scanner from a reader.

use std::io;

use scanner_rust::Scanner;

let mut sc = Scanner::new(io::stdin());
Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub fn new2(reader: R) -> Scanner<R, N>

Create a scanner from a reader and set the buffer size via generics.

use std::io;

use scanner_rust::Scanner;

let mut sc: Scanner<_, 1024> = Scanner::new2(io::stdin());
Source§

impl Scanner<File>

Source

pub fn scan_path<P: AsRef<Path>>(path: P) -> Result<Scanner<File>, ScannerError>

Create a scanner to read data from a file by its path.

use scanner_rust::Scanner;

let mut sc = Scanner::scan_path("Cargo.toml").unwrap();
Source§

impl<const N: usize> Scanner<File, N>

Source

pub fn scan_path2<P: AsRef<Path>>( path: P, ) -> Result<Scanner<File, N>, ScannerError>

Create a scanner to read data from a file by its path and set the buffer size via generics.

use scanner_rust::Scanner;

let mut sc: Scanner<_, 1024> = Scanner::scan_path2("Cargo.toml").unwrap();
Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub unsafe fn remove_heading_bytes_from_buffer( &mut self, number_of_bytes: usize, )

Left shift (if necessary) the buffer to remove bytes from the start of the buffer. Typically, you should use this after peeking the buffer.

§Safety

number_of_bytes must not be greater than the length of the currently buffered data (the length of the slice returned by peek). A larger value underflows the internal buffer length and causes out-of-bounds access afterwards.

Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub fn next_char(&mut self) -> Result<Option<char>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("5 c 中文".as_bytes());

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());
Source

pub fn next_line(&mut self) -> Result<Option<String>, ScannerError>

Read the next line but not include the trailing line character (or line characters like CrLf(\r\n)). If there is nothing to read, it will return Ok(None).

use scanner_rust::Scanner;

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

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());
Source

pub fn next_line_raw(&mut self) -> Result<Option<Vec<u8>>, ScannerError>

Read the next line but not include the trailing line character (or line characters like CrLf(\r\n)) without fully validating UTF-8. If there is nothing to read, it will return Ok(None).

use scanner_rust::Scanner;

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

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

pub fn drop_next_line(&mut self) -> Result<Option<usize>, ScannerError>

Drop the next line but not include the trailing line character (or line characters like CrLf(\r\n)). If there is nothing to read, it will return Ok(None). If there is something to read, it will return Ok(Some(i)). The i is the length of the dropped line.

use scanner_rust::Scanner;

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

assert_eq!(Some(7), sc.drop_next_line().unwrap());
assert_eq!(Some("789 ".into()), sc.next_line().unwrap());
assert_eq!(Some(0), sc.drop_next_line().unwrap());
assert_eq!(Some(" 中文 ".into()), sc.next_line().unwrap());
assert_eq!(None, sc.drop_next_line().unwrap());
Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub fn skip_whitespaces(&mut self) -> Result<bool, ScannerError>

Skip the next whitespaces (javaWhitespace). If there is nothing to read, it will return Ok(false).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2   c".as_bytes());

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());
Source

pub fn next(&mut self) -> Result<Option<String>, ScannerError>

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

use scanner_rust::Scanner;

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

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());
Source

pub fn next_raw(&mut self) -> Result<Option<Vec<u8>>, ScannerError>

Read the next token separated by whitespaces without fully validating UTF-8. If there is nothing to read, it will return Ok(None).

use scanner_rust::Scanner;

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

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

pub fn drop_next(&mut self) -> Result<Option<usize>, ScannerError>

Drop the next token separated by whitespaces. If there is nothing to read, it will return Ok(None). If there is something to read, it will return Ok(Some(i)). The i is the length of the dropped token.

use scanner_rust::Scanner;

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

assert_eq!(Some(3), sc.drop_next().unwrap());
assert_eq!(Some("456".into()), sc.next().unwrap());
assert_eq!(Some(3), sc.drop_next().unwrap());
assert_eq!(Some("中文".into()), sc.next().unwrap());
assert_eq!(None, sc.drop_next().unwrap());
Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub fn next_bytes( &mut self, max_number_of_bytes: usize, ) -> Result<Option<Vec<u8>>, ScannerError>

Read the next bytes. If there is nothing to read, it will return Ok(None).

use scanner_rust::Scanner;

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

assert_eq!(Some("123".into()), sc.next_bytes(3).unwrap());
assert_eq!(Some(" 456".into()), sc.next_bytes(4).unwrap());
assert_eq!(Some("\r\n789 ".into()), sc.next_bytes(6).unwrap());
assert_eq!(Some("中文".into()), sc.next_raw().unwrap());
assert_eq!(Some(" ".into()), sc.next_bytes(2).unwrap());
assert_eq!(None, sc.next_bytes(2).unwrap());
Source

pub fn drop_next_bytes( &mut self, max_number_of_bytes: usize, ) -> Result<Option<usize>, ScannerError>

Drop the next N bytes. If there is nothing to read, it will return Ok(None). If there is something to read, it will return Ok(Some(i)). The i is the length of the actually dropped bytes.

use scanner_rust::Scanner;

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

assert_eq!(Some(7), sc.drop_next_bytes(7).unwrap());
assert_eq!(Some("".into()), sc.next_line().unwrap());
assert_eq!(Some("789 ".into()), sc.next_line().unwrap());
assert_eq!(Some(1), sc.drop_next_bytes(1).unwrap());
assert_eq!(Some(" 中文 ".into()), sc.next_line().unwrap());
assert_eq!(None, sc.drop_next_bytes(1).unwrap());
Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub fn next_until<S: AsRef<str>>( &mut self, boundary: S, ) -> Result<Option<String>, ScannerError>

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

use scanner_rust::Scanner;

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

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

pub fn next_until_raw<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<Vec<u8>>, ScannerError>

Read the next data until it reaches a specific boundary without fully validating UTF-8. If there is nothing to read, it will return Ok(None).

use scanner_rust::Scanner;

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

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

pub fn drop_next_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<usize>, ScannerError>

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

use scanner_rust::Scanner;

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

assert_eq!(Some(7), sc.drop_next_until("\r\n").unwrap());
assert_eq!(Some("789 ".into()), sc.next_line().unwrap());
assert_eq!(Some(0), sc.drop_next_until("\n").unwrap());
assert_eq!(Some(" 中文 ".into()), sc.next_line().unwrap());
assert_eq!(None, sc.drop_next_until("").unwrap());
Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub fn peek(&mut self, shift: bool) -> Result<&[u8], ScannerError>

Fill up the buffer as much as possible and return an immutable slice of all the currently buffered (unread) data. Reading stops at the end of the stream or when the buffer is full. If shift is true, the buffered data is first moved to the front of the buffer so that up to the whole buffer size can be filled; if false, only the space after the current read position is filled.

use scanner_rust::Scanner;

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

assert_eq!("123 456\r\n789 \n\n 中文 ".as_bytes(), sc.peek(false).unwrap());
Source§

impl<R: Read, const N: usize> Scanner<R, N>

Source

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

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_u8().unwrap());
assert_eq!(Some(2), sc.next_u8().unwrap());
Source

pub fn next_u16(&mut self) -> Result<Option<u16>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_u16().unwrap());
assert_eq!(Some(2), sc.next_u16().unwrap());
Source

pub fn next_u32(&mut self) -> Result<Option<u32>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_u32().unwrap());
assert_eq!(Some(2), sc.next_u32().unwrap());
Source

pub fn next_u64(&mut self) -> Result<Option<u64>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_u64().unwrap());
assert_eq!(Some(2), sc.next_u64().unwrap());
Source

pub fn next_u128(&mut self) -> Result<Option<u128>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_u128().unwrap());
assert_eq!(Some(2), sc.next_u128().unwrap());
Source

pub fn next_usize(&mut self) -> Result<Option<usize>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_usize().unwrap());
assert_eq!(Some(2), sc.next_usize().unwrap());
Source

pub fn next_i8(&mut self) -> Result<Option<i8>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_i8().unwrap());
assert_eq!(Some(2), sc.next_i8().unwrap());
Source

pub fn next_i16(&mut self) -> Result<Option<i16>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_i16().unwrap());
assert_eq!(Some(2), sc.next_i16().unwrap());
Source

pub fn next_i32(&mut self) -> Result<Option<i32>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_i32().unwrap());
assert_eq!(Some(2), sc.next_i32().unwrap());
Source

pub fn next_i64(&mut self) -> Result<Option<i64>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_i64().unwrap());
assert_eq!(Some(2), sc.next_i64().unwrap());
Source

pub fn next_i128(&mut self) -> Result<Option<i128>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_i128().unwrap());
assert_eq!(Some(2), sc.next_i128().unwrap());
Source

pub fn next_isize(&mut self) -> Result<Option<isize>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

assert_eq!(Some(1), sc.next_isize().unwrap());
assert_eq!(Some(2), sc.next_isize().unwrap());
Source

pub fn next_f32(&mut self) -> Result<Option<f32>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2.5".as_bytes());

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

pub fn next_f64(&mut self) -> Result<Option<f64>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2.5".as_bytes());

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

impl<R: Read, const N: usize> Scanner<R, N>

Source

pub fn next_u8_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<u8>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_u16_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<u16>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_u32_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<u32>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_u64_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<u64>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_u128_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<u128>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_usize_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<usize>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_i8_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<i8>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_i16_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<i16>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_i32_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<i32>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_i64_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<i64>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_i128_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<i128>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_isize_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<isize>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2".as_bytes());

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

pub fn next_f32_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<f32>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2.5".as_bytes());

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

pub fn next_f64_until<D: ?Sized + AsRef<[u8]>>( &mut self, boundary: &D, ) -> Result<Option<f64>, ScannerError>

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).

use scanner_rust::Scanner;

let mut sc = Scanner::new("1 2.5".as_bytes());

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

Trait Implementations§

Source§

impl<R: Read, const N: usize> Debug for Scanner<R, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, const N: usize> Freeze for Scanner<R, N>
where R: Freeze,

§

impl<R, const N: usize> RefUnwindSafe for Scanner<R, N>
where R: RefUnwindSafe,

§

impl<R, const N: usize> Send for Scanner<R, N>
where R: Send,

§

impl<R, const N: usize> Sync for Scanner<R, N>
where R: Sync,

§

impl<R, const N: usize> Unpin for Scanner<R, N>
where R: Unpin,

§

impl<R, const N: usize> UnsafeUnpin for Scanner<R, N>
where R: UnsafeUnpin,

§

impl<R, const N: usize> UnwindSafe for Scanner<R, N>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.