Struct rustc_span::symbol::Symbol
source · 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
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 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<Symbol> for Symbol
impl PartialOrd<Symbol> for Symbol
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<CTX> ToStableHashKey<CTX> for Symbol
impl<CTX> ToStableHashKey<CTX> for Symbol
impl Copy for Symbol
impl Eq for Symbol
impl StructuralEq for Symbol
impl StructuralPartialEq for Symbol
Auto Trait Implementations§
impl RefUnwindSafe for Symbol
impl Send for Symbol
impl Sync for Symbol
impl Unpin for Symbol
impl UnwindSafe for Symbol
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: 4 bytes