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

source

const fn new(n: u32) -> Self

source

pub fn new_from_decoded(n: u32) -> Self

for use in Decoder only

source

pub fn intern(string: &str) -> Self

Maps a string to its interned representation.

source

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.

source

pub fn as_u32(self) -> u32

source

pub fn is_empty(self) -> bool

source

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

source

fn is_special(self) -> bool

source

fn is_used_keyword_always(self) -> bool

source

fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool

source

fn is_unused_keyword_always(self) -> bool

source

fn is_unused_keyword_conditional( self, edition: impl Copy + FnOnce() -> Edition ) -> bool

source

pub fn is_reserved(self, edition: impl Copy + FnOnce() -> Edition) -> bool

source

pub fn is_path_segment_keyword(self) -> bool

A keyword or reserved identifier that can be used as a path segment.

source

pub fn is_bool_lit(self) -> bool

Returns true if the symbol is true or false.

source

pub fn can_be_raw(self) -> bool

Returns true if this symbol can be a raw identifier.

source

pub fn is_preinterned(self) -> bool

Is this symbol was interned in compiler’s symbols! macro

Trait Implementations§

source§

impl Clone for Symbol

source§

fn clone(&self) -> Symbol

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Symbol

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<D: SpanDecoder> Decodable<D> for Symbol

source§

impl Display for Symbol

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<E: SpanEncoder> Encodable<E> for Symbol

source§

fn encode(&self, s: &mut E)

source§

impl Hash for Symbol

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<CTX> HashStable<CTX> for Symbol

source§

fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)

source§

impl Ord for Symbol

source§

fn cmp(&self, other: &Symbol) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Symbol

source§

fn eq(&self, other: &Symbol) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Symbol

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StableCompare for Symbol

source§

impl<CTX> ToStableHashKey<CTX> for Symbol

source§

impl ToString for Symbol

source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl Copy for Symbol

source§

impl Eq for Symbol

source§

impl StructuralPartialEq for Symbol

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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