[][src]Struct syntax_pos::symbol::Symbol

pub struct Symbol(_);

A symbol is an interned or gensymed string. A gensym is a symbol that is never equal to any other symbol. E.g.:

assert_eq!(Symbol::intern("x"), Symbol::intern("x"))
assert_ne!(Symbol::gensym("x"), Symbol::intern("x"))
assert_ne!(Symbol::gensym("x"), Symbol::gensym("x"))

Conceptually, a gensym can be thought of as a normal symbol with an invisible unique suffix. Gensyms are useful when creating new identifiers that must not match any existing identifiers, e.g. during macro expansion and syntax desugaring.

Internally, a Symbol is implemented as an index, and all operations (including hashing, equality, and ordering) operate on that index. The use of newtype_index! means that Option<Symbol> only takes up 4 bytes, because newtype_index! reserves the last 256 values for tagging purposes.

Note that Symbol cannot directly be a newtype_index! because it implements fmt::Debug, Encodable, and Decodable in special ways.

Methods

impl Symbol[src]

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

Maps a string to its interned representation.

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

Gensyms a new usize, using the current interner.

pub fn gensymed(self) -> Self[src]

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

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

pub fn as_interned_str(self) -> InternedString[src]

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

Trait Implementations

impl Clone for Symbol[src]

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

Performs copy-assignment from source. Read more

impl Ord for Symbol[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

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

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

Restrict a value to a certain interval. Read more

impl Eq for Symbol[src]

impl Copy for Symbol[src]

impl PartialOrd<Symbol> for Symbol[src]

impl PartialEq<Symbol> for Symbol[src]

impl Debug for Symbol[src]

impl Display for Symbol[src]

impl Hash for Symbol[src]

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 Encodable for Symbol[src]

impl Decodable for Symbol[src]

Auto Trait Implementations

impl Send for Symbol

impl Sync for Symbol

Blanket Implementations

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.

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

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

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

impl<T> Encodable for T where
    T: UseSpecializedEncodable + ?Sized
[src]

impl<T> Decodable for T where
    T: UseSpecializedDecodable
[src]

impl<E> SpecializationError for E[src]

impl<T> Erased for T[src]

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

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