Struct cop::symbol::Symbol[][src]

pub struct Symbol<'s>(_);

Shared string with fast cloning, hashing, and equality check.

Cloning, hashing, and equality checking is performed on the address of the pointer, making them constant-time operations.

Note that two different symbols pointing to equivalent strings are not equal, as well as their hashes:

let h1 = String::from("Hello");
let h2 = String::from("Hello");
let wl = String::from("World");
let s1 = Symbol::new(&h1);
let s2 = Symbol::new(&h2);
let s3 = Symbol::new(&wl);

assert_eq!(s1, s1);
assert_eq!(s1, s1.clone());
assert_ne!(s1, s2);
assert_ne!(s1, s3);

let hash = |s: Symbol| -> u64 {
    let mut hasher = DefaultHasher::new();
    s.hash(&mut hasher);
    hasher.finish()
};

assert_eq!(hash(s1), hash(s1.clone()));
assert_ne!(hash(s1), hash(s2));

Implementations

impl<'s> Symbol<'s>[src]

pub fn new(s: &'s str) -> Self[src]

Trait Implementations

impl<'s> Clone for Symbol<'s>[src]

impl<'s> Copy for Symbol<'s>[src]

impl<'s> Debug for Symbol<'s>[src]

impl<'s> Display for Symbol<'s>[src]

impl<'s> Eq for Symbol<'s>[src]

impl<'s> Hash for Symbol<'s>[src]

impl<'s> PartialEq<Symbol<'s>> for Symbol<'s>[src]

Auto Trait Implementations

impl<'s> RefUnwindSafe for Symbol<'s>

impl<'s> Send for Symbol<'s>

impl<'s> Sync for Symbol<'s>

impl<'s> Unpin for Symbol<'s>

impl<'s> UnwindSafe for Symbol<'s>

Blanket Implementations

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

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

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

impl<T> CallHasher for T where
    T: Hash

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> ToString for T where
    T: Display + ?Sized
[src]

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.