Skip to main content

Lit

Enum Lit 

Source
pub enum Lit {
    Int(LitInt),
    Float(LitFloat),
    Str(LitStr),
    ByteStr(LitByteStr),
    CStr(LitCStr),
    Char(LitChar),
    Byte(LitByte),
    Bool(LitBool),
    Verbatim(LitVerbatim),
}
Expand description

A parsed Rust literal token.

Variants§

§

Int(LitInt)

§

Float(LitFloat)

§

Str(LitStr)

§

ByteStr(LitByteStr)

§

CStr(LitCStr)

§

Char(LitChar)

§

Byte(LitByte)

§

Bool(LitBool)

§

Verbatim(LitVerbatim)

Implementations§

Source§

impl Lit

Source

pub fn f32_suffixed(value: f32) -> Self

Source

pub fn f32_unsuffixed(value: f32) -> Self

Source

pub fn f64_suffixed(value: f64) -> Self

Source

pub fn f64_unsuffixed(value: f64) -> Self

Source§

impl Lit

Source

pub fn u8_suffixed(value: u8) -> Self

Source

pub fn u8_unsuffixed(value: u8) -> Self

Source

pub fn u16_suffixed(value: u16) -> Self

Source

pub fn u16_unsuffixed(value: u16) -> Self

Source

pub fn u32_suffixed(value: u32) -> Self

Source

pub fn u32_unsuffixed(value: u32) -> Self

Source

pub fn u64_suffixed(value: u64) -> Self

Source

pub fn u64_unsuffixed(value: u64) -> Self

Source

pub fn usize_suffixed(value: usize) -> Self

Source

pub fn usize_unsuffixed(value: usize) -> Self

Source

pub fn i8_suffixed(value: i8) -> Self

Source

pub fn i8_unsuffixed(value: i8) -> Self

Source

pub fn i16_suffixed(value: i16) -> Self

Source

pub fn i16_unsuffixed(value: i16) -> Self

Source

pub fn i32_suffixed(value: i32) -> Self

Source

pub fn i32_unsuffixed(value: i32) -> Self

Source

pub fn i64_suffixed(value: i64) -> Self

Source

pub fn i64_unsuffixed(value: i64) -> Self

Source

pub fn isize_suffixed(value: isize) -> Self

Source

pub fn isize_unsuffixed(value: isize) -> Self

Source§

impl Lit

Source

pub fn string(value: &str) -> Self

Source

pub fn char(value: char) -> Self

Source

pub fn from_repr(repr: &str, span: Span) -> Self

Classify and decode an arbitrary literal repr into the matching variant. Used by the proc-macro bridges, which only have the source text. Falls back to LitVerbatim for anything that doesn’t lex as a known literal.

Source

pub fn is_int(&self) -> bool

Source

pub fn is_float(&self) -> bool

Source

pub fn is_str(&self) -> bool

Source

pub fn is_c_str(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_char(&self) -> bool

Source

pub fn is_byte(&self) -> bool

Source

pub fn is_byte_str(&self) -> bool

Source

pub fn is_verbatim(&self) -> bool

Source

pub fn as_str(&self) -> Option<&LitStr>

Source

pub fn as_c_str(&self) -> Option<&LitCStr>

Source

pub fn as_bool(&self) -> Option<&LitBool>

Source

pub fn as_int(&self) -> Option<&LitInt>

Source

pub fn as_float(&self) -> Option<&LitFloat>

Source

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

Source

pub fn as_byte(&self) -> Option<&LitByte>

Source

pub fn as_byte_str(&self) -> Option<&LitByteStr>

Source

pub fn to_token_tree(&self) -> TokenTree

Source

pub fn into_token_tree(self) -> TokenTree

Source

pub fn repr(&self) -> &str

Source

pub fn span(&self) -> Span

Source

pub fn set_span(&mut self, span: Span)

Trait Implementations§

Source§

impl Clone for Lit

Source§

fn clone(&self) -> Lit

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Lit

Source§

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

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

impl Display for Lit

Source§

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

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

impl Eq for Lit

Source§

impl From<Lit> for Literal

Source§

fn from(value: Lit) -> Self

Converts to this type from the input type.
Source§

impl From<Lit> for TokenTree

Source§

fn from(value: Lit) -> Self

Converts to this type from the input type.
Source§

impl From<LitBool> for Lit

Source§

fn from(value: LitBool) -> Self

Converts to this type from the input type.
Source§

impl From<LitByte> for Lit

Source§

fn from(value: LitByte) -> Self

Converts to this type from the input type.
Source§

impl From<LitByteStr> for Lit

Source§

fn from(value: LitByteStr) -> Self

Converts to this type from the input type.
Source§

impl From<LitCStr> for Lit

Source§

fn from(value: LitCStr) -> Self

Converts to this type from the input type.
Source§

impl From<LitChar> for Lit

Source§

fn from(value: LitChar) -> Self

Converts to this type from the input type.
Source§

impl From<LitF32> for Lit

Source§

fn from(value: LitF32) -> Self

Converts to this type from the input type.
Source§

impl From<LitF64> for Lit

Source§

fn from(value: LitF64) -> Self

Converts to this type from the input type.
Source§

impl From<LitInt> for Lit

Source§

fn from(value: LitInt) -> Self

Converts to this type from the input type.
Source§

impl From<LitStr> for Lit

Source§

fn from(value: LitStr) -> Self

Converts to this type from the input type.
Source§

impl From<LitVerbatim> for Lit

Source§

fn from(value: LitVerbatim) -> Self

Converts to this type from the input type.
Source§

impl From<Literal> for Lit

Source§

fn from(value: Literal) -> Self

Converts to this type from the input type.
Source§

impl Hash for Lit

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Lit

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Scan for Lit

Source§

fn scan(cursor: Cursor<'_>) -> Result<(Cursor<'_>, Self), LexError>

Source§

impl Spanner for Lit

Source§

fn span(&self) -> Span

Source§

impl StructuralPartialEq for Lit

Source§

impl ToTokens for Lit

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Auto Trait Implementations§

§

impl !Send for Lit

§

impl !Sync for Lit

§

impl Freeze for Lit

§

impl RefUnwindSafe for Lit

§

impl Unpin for Lit

§

impl UnsafeUnpin for Lit

§

impl UnwindSafe for Lit

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<X> ToTokenStream for X
where X: ToTokens + ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.