pub(in attributes) struct Symbol(SymbolIndex);Expand description
An interned UTF-8 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: SymbolIndexImplementations§
Source§impl Symbol
impl Symbol
Sourcepub const fn new(n: u32) -> Symbol
pub const fn new(n: u32) -> Symbol
Avoid this except for things like deserialization of previously
serialized symbols, and testing. Use intern instead.
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
pub fn is_reserved(self, edition: impl Copy + FnOnce() -> Edition) -> bool
pub fn is_weak(self) -> 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_predefined(index: u32) -> bool
pub fn is_predefined(index: u32) -> bool
Was this symbol index predefined in the compiler’s symbols! macro?
Note: this applies to both Symbols and ByteSymbols, which is why it
takes a u32 argument instead of a &self argument. Use with care.
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<SipHasher128>)
Source§impl IntoDiagArg for Symbol
impl IntoDiagArg for Symbol
Source§fn into_diag_arg(self, path: &mut Option<PathBuf>) -> DiagArgValue
fn into_diag_arg(self, path: &mut Option<PathBuf>) -> DiagArgValue
Source§impl Ord for Symbol
impl Ord for Symbol
Source§impl PartialOrd for Symbol
impl PartialOrd for Symbol
Source§impl PrintAttribute for Symbol
impl PrintAttribute for Symbol
Source§fn should_render(&self) -> bool
fn should_render(&self) -> bool
fn print_attribute(&self, p: &mut Printer)
Source§impl StableCompare for Symbol
impl StableCompare for Symbol
const CAN_USE_UNSTABLE_SORT: bool = true
fn stable_cmp(&self, other: &Symbol) -> 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<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T
fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
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<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for T
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