Enum scanlex::Token

source ·
pub enum Token {
    Num(f64),
    Int(i64),
    Str(String),
    Iden(String),
    Char(char),
    Error(ScanError),
    End,
}
Expand description

Represents a token returned by Scanner::get

Variants§

§

Num(f64)

a floating-point number, stored as double-precision float

§

Int(i64)

an integer, stored as eight-byte unsigned

§

Str(String)

a quoted string

§

Iden(String)

an identifier \a+[\a\d_]*

§

Char(char)

a character (anything not recognized as any of the above

§

Error(ScanError)

represents an error

§

End

end of stream

Implementations§

source§

impl Token

source

pub fn finished(&self) -> bool

is this the end token?

source

pub fn is_float(&self) -> bool

is this token a float?

source

pub fn to_float(self) -> Option<f64>

extract the float

source

pub fn to_float_result(self) -> Result<f64, ScanError>

extract the float, or complain

source

pub fn is_integer(&self) -> bool

is this token an integer?

source

pub fn to_integer(self) -> Option<i64>

extract the integer

source

pub fn to_integer_result(self) -> Result<i64, ScanError>

extract the integer, or complain

source

pub fn to_int_result<I: Int>(self) -> Result<I::Type, ScanError>

extract the integer as a particular subtype

source

pub fn is_number(&self) -> bool

is this token an integer?

source

pub fn to_number(self) -> Option<f64>

extract the number, not caring about float or integer

source

pub fn to_number_result(self) -> Result<f64, ScanError>

extract the number, not caring about float or integer, or complain

source

pub fn is_string(&self) -> bool

is this token a string?

source

pub fn to_string(self) -> Option<String>

extract the string

source

pub fn as_string(&self) -> Option<&str>

extract a reference the string

source

pub fn to_string_result(self) -> Result<String, ScanError>

extract the string, or complain

source

pub fn is_iden(&self) -> bool

is this token an identifier?

source

pub fn to_iden(self) -> Option<String>

extract the identifier

source

pub fn as_iden(&self) -> Option<&str>

extract a reference to the identifier

source

pub fn to_iden_result(self) -> Result<String, ScanError>

extract the identifier, or complain

source

pub fn is_char(&self) -> bool

is this token a character?

source

pub fn to_char(self) -> Option<char>

extract the character

source

pub fn as_char(&self) -> Option<char>

extract the character

source

pub fn to_char_result(self) -> Result<char, ScanError>

extract the character, or complain

source

pub fn is_error(&self) -> bool

is this token an error?

source

pub fn to_error(self) -> Option<ScanError>

extract the error

Trait Implementations§

source§

impl Debug for Token

source§

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

Formats the value using the given formatter. Read more
source§

impl PartialEq for Token

source§

fn eq(&self, other: &Token) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Token

Auto Trait Implementations§

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Send for Token

§

impl Sync for Token

§

impl Unpin for Token

§

impl UnwindSafe for Token

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>,

§

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>,

§

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.