Struct rustc_span::symbol::Symbol[][src]

pub struct Symbol(SymbolIndex);

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.

Implementations

impl Symbol[src]

const fn new(n: u32) -> Self[src]

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

Maps a string to its interned representation.

pub fn as_str(self) -> SymbolStr[src]

Convert to a SymbolStr. This is a slowish operation because it requires locking the symbol interner.

pub fn as_u32(self) -> u32[src]

pub fn is_empty(self) -> bool[src]

pub fn to_ident_string(self) -> String[src]

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.

impl Symbol[src]

fn is_special(self) -> bool[src]

fn is_used_keyword_always(self) -> bool[src]

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

fn is_unused_keyword_always(self) -> bool[src]

fn is_unused_keyword_conditional(
    self,
    edition: impl FnOnce() -> Edition
) -> bool
[src]

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

pub fn is_path_segment_keyword(self) -> bool[src]

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

pub fn is_bool_lit(self) -> bool[src]

Returns true if the symbol is true or false.

pub fn can_be_raw(self) -> bool[src]

Returns true if this symbol can be a raw identifier.

Trait Implementations

impl Clone for Symbol[src]

fn clone(&self) -> Symbol[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Symbol[src]

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

Formats the value using the given formatter. Read more

impl<D: Decoder> Decodable<D> for Symbol[src]

impl Display for Symbol[src]

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

Formats the value using the given formatter. Read more

impl<S: Encoder> Encodable<S> for Symbol[src]

fn encode(&self, s: &mut S) -> Result<(), S::Error>[src]

impl Hash for Symbol[src]

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

Feeds this value into the given Hasher. Read more

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

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

impl<CTX> HashStable<CTX> for Symbol[src]

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

impl Ord for Symbol[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<Symbol> for Symbol[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Symbol) -> bool[src]

This method tests for !=.

impl PartialOrd<Symbol> for Symbol[src]

fn partial_cmp(&self, other: &Symbol) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<CTX> ToStableHashKey<CTX> for Symbol[src]

impl Copy for Symbol[src]

impl Eq for Symbol[src]

impl StructuralEq for Symbol[src]

impl StructuralPartialEq for Symbol[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.