[−][src]Struct kontroli::scope::Symbol
Shared string with fast cloning, hashing, and equality check.
This is implemented using a reference-counted pointer. 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));
To consistently assign the same symbols to equivalent strings,
you can use the Symbols
type.
Implementations
impl<'s> Symbol<'s>
[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]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,