pub enum LitKind {
Str(Symbol, StrStyle),
ByteStr(ByteSymbol, StrStyle),
CStr(ByteSymbol, 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(ByteSymbol, StrStyle)
A byte string (b"foo"). The symbol is unescaped, and so may differ
from the original token’s symbol.
CStr(ByteSymbol, StrStyle)
A C String (c"foo"). Guaranteed to only have \0 at the end. The
symbol is unescaped, and so may differ from the original token’s
symbol.
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 Copy for LitKind
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§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>
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: 7 bytesCStr: 7 bytesByte: 1 byteChar: 7 bytesInt: 23 bytesFloat: 7 bytesBool: 1 byteErr: 0 bytes