Struct nekolib::utils::scanner::Scanner

source ·
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

source

pub fn from_stdin() -> Result<Self, Error>

source

pub fn next<T: Scan>(&mut self) -> Result<T, <T as Scan>::Err>

source

pub fn next_m1<T>(&mut self) -> Result<T, <T as Scan>::Err>where T: Scan + Sub<Output = T> + From<u8>,

source

pub fn next_n<T>(&mut self, n: usize) -> Result<Vec<T>, <T as Scan>::Err>where T: Scan + Clone,

source

pub fn get_while<P>(&mut self, pat: P) -> &strwhere P: Fn(char) -> bool,

source

pub fn get_line(&mut self) -> &str

source

pub fn ignore(&mut self)

source

pub fn ignore_while<P>(&mut self, pat: P)where P: Fn(char) -> bool,

Trait Implementations§

source§

impl From<String> for Scanner

source§

fn from(buf: String) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V