pub struct Symbol(SymbolIndex);
Expand description
An interned string.
Internally, a Symbol
is implemented as an index, and all operations
(including hashing, equality, and ordering) operate on that index. The use
of rustc_index::newtype_index!
means that Option<Symbol>
only takes up 4 bytes,
because rustc_index::newtype_index!
reserves the last 256 values for tagging purposes.
Note that Symbol
cannot directly be a rustc_index::newtype_index!
because it
implements fmt::Debug
, Encodable
, and Decodable
in special ways.
Tuple Fields§
§0: SymbolIndex
Implementations§
Source§impl Symbol
impl Symbol
const fn new(n: u32) -> Self
Sourcepub fn new_from_decoded(n: u32) -> Self
pub fn new_from_decoded(n: u32) -> Self
for use in Decoder only
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Access the underlying string. This is a slowish operation because it requires locking the symbol interner.
Note that the lifetime of the return value is a lie. It’s not the same
as &self
, but actually tied to the lifetime of the underlying
interner. Interners are long-lived, and there are very few of them, and
this function is typically used for short-lived things, so in practice
it works out ok.
pub fn as_u32(self) -> u32
pub fn is_empty(self) -> bool
Sourcepub fn to_ident_string(self) -> String
pub fn to_ident_string(self) -> String
This method is supposed to be used in error messages, so it’s expected to be
identical to printing the original identifier token written in source code
(token_to_string
, Ident::to_string
), except that symbols don’t keep the rawness flag
or edition, so we have to guess the rawness using the global edition.
Source§impl Symbol
impl Symbol
Sourcepub fn is_any_keyword(self) -> bool
pub fn is_any_keyword(self) -> bool
Don’t use this unless you’re doing something very loose and heuristic-y.
fn is_special(self) -> bool
fn is_used_keyword_always(self) -> bool
fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool
fn is_unused_keyword_always(self) -> bool
fn is_unused_keyword_conditional( self, edition: impl Copy + FnOnce() -> Edition, ) -> bool
pub fn is_reserved(self, edition: impl Copy + FnOnce() -> Edition) -> bool
Sourcepub fn is_path_segment_keyword(self) -> bool
pub fn is_path_segment_keyword(self) -> bool
A keyword or reserved identifier that can be used as a path segment.
Sourcepub fn is_bool_lit(self) -> bool
pub fn is_bool_lit(self) -> bool
Returns true
if the symbol is true
or false
.
Sourcepub fn can_be_raw(self) -> bool
pub fn can_be_raw(self) -> bool
Returns true
if this symbol can be a raw identifier.
Sourcepub fn is_preinterned(self) -> bool
pub fn is_preinterned(self) -> bool
Is this symbol was interned in compiler’s symbols!
macro
Trait Implementations§
Source§impl<CTX> HashStable<CTX> for Symbol
impl<CTX> HashStable<CTX> for Symbol
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)
Source§impl Ord for Symbol
impl Ord for Symbol
Source§impl PartialOrd for Symbol
impl PartialOrd for Symbol
Source§impl StableCompare for Symbol
impl StableCompare for Symbol
const CAN_USE_UNSTABLE_SORT: bool = true
fn stable_cmp(&self, other: &Self) -> Ordering
Source§impl<CTX> ToStableHashKey<CTX> for Symbol
impl<CTX> ToStableHashKey<CTX> for Symbol
impl Copy for Symbol
impl Eq for Symbol
impl StructuralPartialEq for Symbol
Auto Trait Implementations§
impl DynSend for Symbol
impl DynSync for Symbol
impl Freeze for Symbol
impl RefUnwindSafe for Symbol
impl Send for Symbol
impl Sync for Symbol
impl Unpin for Symbol
impl UnwindSafe for Symbol
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> Comparable<K> for Q
impl<Q, K> Comparable<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§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: 4 bytes