Struct rsjsonnet_lang::interner::InternedStr
source · pub struct InternedStr { /* private fields */ }Expand description
A reference counted interned string.
Cloning will increase the reference count and is equivalent to calling
StrInterner::intern with the same string value.
Also implements Eq, Ord and Hash. Note that
comparison and hashing is done on the internal pointer value, not the actual
string value. This means that:
- It does not make sense to compare
InternedStrvalues from differentStrInternerinstances, Ordshould not be relied to be deterministic.
let interner = rsjsonnet_lang::interner::StrInterner::new();
let a1 = interner.intern("a");
let b1 = interner.intern("b");
let a2 = interner.intern("a");
let b2 = interner.intern("b");
// Of course, they are equal.
assert_eq!(a1, a2);
// "a" and "b" are not equal, but there is no guarantee on the exact ordering.
let cmp1 = a1.cmp(&b1);
assert_ne!(cmp1, std::cmp::Ordering::Equal);
// But the ordering is consistent because they came from the same interner.
let cmp2 = a2.cmp(&b2);
assert_eq!(cmp1, cmp2);Implementations§
Trait Implementations§
source§impl Clone for InternedStr
impl Clone for InternedStr
source§fn clone(&self) -> InternedStr
fn clone(&self) -> InternedStr
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for InternedStr
impl Debug for InternedStr
source§impl Hash for InternedStr
impl Hash for InternedStr
source§impl Ord for InternedStr
impl Ord for InternedStr
source§fn cmp(&self, other: &InternedStr) -> Ordering
fn cmp(&self, other: &InternedStr) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for InternedStr
impl PartialEq for InternedStr
source§fn eq(&self, other: &InternedStr) -> bool
fn eq(&self, other: &InternedStr) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd for InternedStr
impl PartialOrd for InternedStr
source§fn partial_cmp(&self, other: &InternedStr) -> Option<Ordering>
fn partial_cmp(&self, other: &InternedStr) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Eq for InternedStr
impl StructuralPartialEq for InternedStr
Auto Trait Implementations§
impl Freeze for InternedStr
impl RefUnwindSafe for InternedStr
impl !Send for InternedStr
impl !Sync for InternedStr
impl Unpin for InternedStr
impl UnwindSafe for InternedStr
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)