pub enum LitKind {
Str(Symbol, StrStyle),
ByteStr(Lrc<[u8]>, StrStyle),
CStr(Lrc<[u8]>, StrStyle),
Byte(u8),
Char(char),
Int(Pu128, LitIntType),
Float(Symbol, LitFloatType),
Bool(bool),
Err(ErrorGuaranteed),
}
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.
CStr(Lrc<[u8]>, StrStyle)
A C String (c"foo"
). Guaranteed to only have \0
at the end.
Byte(u8)
A byte char (b'f'
).
Char(char)
A character literal ('a'
).
Int(Pu128, 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(ErrorGuaranteed)
Placeholder for a literal that wasn’t well-formed in some way.
Implementations§
source§impl LitKind
impl LitKind
pub fn str(&self) -> Option<Symbol>
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<__D: SpanDecoder> Decodable<__D> for LitKind
impl<__D: SpanDecoder> Decodable<__D> for LitKind
source§impl<__E: SpanEncoder> Encodable<__E> for LitKind
impl<__E: SpanEncoder> Encodable<__E> for LitKind
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 StructuralPartialEq for LitKind
Auto Trait Implementations§
impl DynSend for LitKind
impl DynSync for LitKind
impl Freeze for LitKind
impl RefUnwindSafe for LitKind
impl Send for LitKind
impl Sync for LitKind
impl Unpin for LitKind
impl UnwindSafe for LitKind
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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 bytesCStr
: 23 bytesByte
: 1 byteChar
: 7 bytesInt
: 23 bytesFloat
: 7 bytesBool
: 1 byteErr
: 0 bytes