pub struct Symbol<'s>(/* private fields */);
Expand description
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§
Trait Implementations§
source§impl<'s> PartialEq<Symbol<'s>> for Symbol<'s>
impl<'s> PartialEq<Symbol<'s>> for Symbol<'s>
impl<'s> Copy for Symbol<'s>
impl<'s> Eq for Symbol<'s>
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more