pub struct Interned<T> { /* private fields */ }Expand description
A statically interned value of type T.
An Interned<T> is a compact, copyable handle that deduplicates equal values
and compares in O(1) using its index. It behaves like &'static T via
Deref, and can be obtained with [InternExtTrait::intern] or
Interned::intern.
Implementations§
Source§impl<T: Internable> Interned<T>
impl<T: Internable> Interned<T>
Sourcepub fn intern(value: &T) -> Self
pub fn intern(value: &T) -> Self
Interns a value and returns its compact handle.
If an equal value has been interned before, this returns the existing handle; otherwise it inserts the value into the global table.
Sourcepub fn get(self) -> &'static T
pub fn get(self) -> &'static T
Returns a &'static T for this handle.
§Safety & Lifetimes
This method relies on the fact that the backing storage lives for the
entire program (it is kept in a static global table). The 'static
reference is sound as long as values are never removed from that table.
This implementation uses transmute internally for that reason.
Trait Implementations§
Source§impl<T: Internable> AsRef<T> for Interned<T>
impl<T: Internable> AsRef<T> for Interned<T>
Source§impl<T: Internable> Deref for Interned<T>
impl<T: Internable> Deref for Interned<T>
Source§impl<'a, T: Deserialize<'a> + Internable> Deserialize<'a> for Interned<T>
impl<'a, T: Deserialize<'a> + Internable> Deserialize<'a> for Interned<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'a>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'a>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: JsonSchema> JsonSchema for Interned<T>
impl<T: JsonSchema> JsonSchema for Interned<T>
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref keyword. Read moreSource§impl<T: Eq> Ord for Interned<T>
impl<T: Eq> Ord for Interned<T>
Source§impl<T: Eq> PartialOrd for Interned<T>
impl<T: Eq> PartialOrd for Interned<T>
impl<T> Copy for Interned<T>
impl<T: Eq> Eq for Interned<T>
impl<T> StructuralPartialEq for Interned<T>
Auto Trait Implementations§
impl<T> Freeze for Interned<T>
impl<T> RefUnwindSafe for Interned<T>where
T: RefUnwindSafe,
impl<T> Send for Interned<T>where
T: Send,
impl<T> Sync for Interned<T>where
T: Sync,
impl<T> Unpin for Interned<T>where
T: Unpin,
impl<T> UnwindSafe for Interned<T>where
T: UnwindSafe,
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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more