pub enum LitKind {
Str(Symbol, StrStyle),
ByteStr(Lrc<[u8]>),
Byte(u8),
Char(char),
Int(u128, LitIntType),
Float(Symbol, LitFloatType),
Bool(bool),
Err(Symbol),
}
Expand description
Literal kind.
E.g., "foo"
, 42
, 12.34
, or bool
.
Variants
Str(Symbol, StrStyle)
A string literal ("foo"
).
ByteStr(Lrc<[u8]>)
A byte string (b"foo"
).
Byte(u8)
A byte char (b'f'
).
Char(char)
A character literal ('a'
).
Int(u128, LitIntType)
An integer literal (1
).
Float(Symbol, LitFloatType)
A float literal (1f64
or 1E10f64
).
Bool(bool)
A boolean literal.
Err(Symbol)
Placeholder for a literal that wasn’t well-formed in some way.
Implementations
sourceimpl LitKind
impl LitKind
sourcepub fn from_lit_token(lit: Lit) -> Result<LitKind, LitError>
pub fn from_lit_token(lit: Lit) -> Result<LitKind, LitError>
Converts literal token into a semantic literal.
sourcepub fn to_lit_token(&self) -> Lit
pub fn to_lit_token(&self) -> Lit
Attempts to recover a token from semantic literal. This function is used when the original token doesn’t exist (e.g. the literal is created by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
sourceimpl LitKind
impl LitKind
sourcepub fn is_bytestr(&self) -> bool
pub fn is_bytestr(&self) -> bool
Returns true
if this literal is byte literal string.
sourcepub fn is_numeric(&self) -> bool
pub fn is_numeric(&self) -> bool
Returns true
if this is a numeric literal.
sourcepub fn is_unsuffixed(&self) -> bool
pub fn is_unsuffixed(&self) -> bool
Returns true
if this literal has no suffix.
Note: this will return true for literals with prefixes such as raw strings and byte strings.
sourcepub fn is_suffixed(&self) -> bool
pub fn is_suffixed(&self) -> bool
Returns true
if this literal has a suffix.
Trait Implementations
sourceimpl<__CTX> HashStable<__CTX> for LitKind where
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for LitKind where
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
impl Eq for LitKind
impl StructuralEq for LitKind
impl StructuralPartialEq for LitKind
Auto Trait Implementations
impl RefUnwindSafe for LitKind
impl !Send for LitKind
impl !Sync for LitKind
impl Unpin for LitKind
impl UnwindSafe for LitKind
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes
Size for each variant:
Str
: 7 bytesByteStr
: 23 bytesByte
: 1 byteChar
: 7 bytesInt
: 23 bytesFloat
: 7 bytesBool
: 1 byteErr
: 7 bytes