pub enum LitKind {
Str(Symbol, StrStyle),
ByteStr(Lrc<[u8]>, StrStyle),
Byte(u8),
Char(char),
Int(u128, LitIntType),
Float(Symbol, LitFloatType),
Bool(bool),
Err,
}
Expand description
This type is used within both ast::MetaItemLit
and hir::Lit
.
Note that the entire literal (including the suffix) is considered when
deciding the LitKind
. This means that float literals like 1f32
are
classified by this type as Float
. This is different to token::LitKind
which does not consider the suffix.
Variants§
Str(Symbol, StrStyle)
A string literal ("foo"
). The symbol is unescaped, and so may differ
from the original token’s symbol.
ByteStr(Lrc<[u8]>, StrStyle)
A byte string (b"foo"
). Not stored as a symbol because it might be
non-utf8, and symbols only allow utf8 strings.
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 (1.0
, 1f64
or 1E10f64
). The pre-suffix part is
stored as a symbol rather than f64
so that LitKind
can impl Eq
and Hash
.
Bool(bool)
A boolean literal (true
, false
).
Err
Placeholder for a literal that wasn’t well-formed in some way.
Implementations§
source§impl 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§
source§impl<__CTX> HashStable<__CTX> for LitKindwhere
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for LitKindwhere
__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§
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
: 0 bytes