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
sourceimpl Symbol
impl Symbol
const fn new(n: u32) -> Self
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.
sourceimpl 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.
Trait Implementations
sourceimpl<CTX> HashStable<CTX> for Symbol
impl<CTX> HashStable<CTX> for Symbol
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)
sourceimpl Ord for Symbol
impl Ord for Symbol
sourceimpl PartialOrd<Symbol> for Symbol
impl PartialOrd<Symbol> for Symbol
sourcefn partial_cmp(&self, other: &Symbol) -> Option<Ordering>
fn partial_cmp(&self, other: &Symbol) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
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