pub struct Scanner { /* private fields */ }
Expand description
スキャナ。
文字列スライスを読み、所望の型に変換する。
Examples
use std::num::ParseIntError;
use nekolib::utils::Scanner;
let mut p: Scanner = "1 2 a\nb 3".to_string().into();
assert_eq!(p.next::<i32>(), Ok(1));
assert_eq!(p.next::<i32>(), Ok(2));
// `"a"` => `ParseIntError { kind: InvalidDigit }`
assert!(p.next::<i32>().is_err());
assert_eq!(p.next::<char>(), Ok('b'));
assert_eq!(p.next::<String>(), Ok("3".to_string()));
assert_eq!(p.next::<String>(), Ok("".to_string()));
// `""` => `ParseIntError { kind: Empty }`
assert!(p.next::<i32>().is_err());
// `""` => `ParseCharError { kind: EmptyString }`
assert!(p.next::<char>().is_err());
// ok again, as `&str` => `String` never fails
assert_eq!(p.next::<String>(), Ok("".to_string()));
Implementations§
source§impl Scanner
impl Scanner
pub fn from_stdin() -> Result<Self, Error>
pub fn next<T: Scan>(&mut self) -> Result<T, <T as Scan>::Err>
pub fn next_m1<T>(&mut self) -> Result<T, <T as Scan>::Err>where T: Scan + Sub<Output = T> + From<u8>,
pub fn next_n<T>(&mut self, n: usize) -> Result<Vec<T>, <T as Scan>::Err>where T: Scan + Clone,
pub fn get_while<P>(&mut self, pat: P) -> &strwhere P: Fn(char) -> bool,
pub fn get_line(&mut self) -> &str
pub fn ignore(&mut self)
pub fn ignore_while<P>(&mut self, pat: P)where P: Fn(char) -> bool,
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Scanner
impl Send for Scanner
impl Sync for Scanner
impl Unpin for Scanner
impl UnwindSafe for Scanner
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more