Symbol in rustc_span::symbol - Rust (original) (raw)

pub 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.

Source§

Source

Avoid this except for things like deserialization of previously serialized symbols, and testing. Use intern instead.

Source

Maps a string to its interned representation.

Source

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

Source

Source

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

Checks if self is similar to any symbol in candidates.

The returned boolean represents whether the candidate is the same symbol with a different casing.

All the candidates are assumed to be lowercase.

Source§

Source

Source

Source

Source

Source

Source

Source

Source

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

Source

Returns true if the symbol is true or false.

Source

Returns true if this symbol can be a raw identifier.

Source

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.

§

§

§

§

§

§

§

§

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