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> AstVisitable for Interned<T>
impl<T> AstVisitable for Interned<T>
Source§fn drive_map<V: AstVisitorMut>(&mut self, v: &mut V)
fn drive_map<V: AstVisitorMut>(&mut self, v: &mut V)
Recursively visit this type with the provided visitor. This calls the visitor’s
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive<V: AstVisitor>(&self, v: &mut V)
fn drive<V: AstVisitor>(&self, v: &mut V)
Recursively visit this type with the provided visitor. This calls the visitor’s
visit_$any
method if it exists, otherwise visit_inner.Source§impl<T> AstVisitable for Interned<T>
impl<T> AstVisitable for Interned<T>
Source§fn drive<V: AstEarlyExitVisitor>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive<V: AstEarlyExitVisitor>(&self, v: &mut V) -> ControlFlow<V::Break>
Recursively visit this type with the provided visitor. This calls the visitor’s
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_mut<V: AstEarlyExitVisitorMut>(
&mut self,
v: &mut V,
) -> ControlFlow<V::Break>
fn drive_mut<V: AstEarlyExitVisitorMut>( &mut self, v: &mut V, ) -> ControlFlow<V::Break>
Recursively visit this type with the provided visitor. This calls the visitor’s
visit_$any
method if it exists, otherwise visit_inner.impl<T> Copy 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
impl<T: Eq> Eq for Interned<T>
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>
1.21.0 (const: unstable) · 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<T: Eq> PartialOrd for Interned<T>
impl<T: Eq> PartialOrd for Interned<T>
impl<T: PartialEq> 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> UnsafeUnpin for Interned<T>
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ExtensionPoint for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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