pub struct TypedMetadata { /* private fields */ }Expand description
Typed metadata bag — stores arbitrary Send + Sync + 'static values
keyed by their concrete type.
At most one value per concrete type. To store multiple values of the same underlying type, use distinct newtype wrappers.
§Example
use nv_core::TypedMetadata;
#[derive(Clone, Debug, PartialEq)]
struct DetectorScore(f32);
#[derive(Clone, Debug, PartialEq)]
struct TrackerScore(f32);
let mut meta = TypedMetadata::new();
meta.insert(DetectorScore(0.95));
meta.insert(TrackerScore(0.8));
assert_eq!(meta.get::<DetectorScore>(), Some(&DetectorScore(0.95)));
assert_eq!(meta.get::<TrackerScore>(), Some(&TrackerScore(0.8)));
assert_eq!(meta.len(), 2);Implementations§
Source§impl TypedMetadata
impl TypedMetadata
Sourcepub fn new() -> TypedMetadata
pub fn new() -> TypedMetadata
Create an empty metadata bag.
Sourcepub fn insert<T>(&mut self, val: T) -> Option<T>
pub fn insert<T>(&mut self, val: T) -> Option<T>
Insert a value. If a value of this type already exists, it is replaced and the old value is returned.
Sourcepub fn get<T>(&self) -> Option<&T>where
T: 'static,
pub fn get<T>(&self) -> Option<&T>where
T: 'static,
Get a reference to the stored value of type T, if present.
Sourcepub fn get_mut<T>(&mut self) -> Option<&mut T>where
T: 'static,
pub fn get_mut<T>(&mut self) -> Option<&mut T>where
T: 'static,
Get a mutable reference to the stored value of type T, if present.
Sourcepub fn remove<T>(&mut self) -> Option<T>where
T: 'static,
pub fn remove<T>(&mut self) -> Option<T>where
T: 'static,
Remove and return the stored value of type T, if present.
Sourcepub fn contains<T>(&self) -> boolwhere
T: 'static,
pub fn contains<T>(&self) -> boolwhere
T: 'static,
Returns true if a value of type T is stored.
Sourcepub fn merge(&mut self, other: TypedMetadata)
pub fn merge(&mut self, other: TypedMetadata)
Merge another TypedMetadata into this one.
Keys present in other overwrite keys in self (last-writer-wins).
Trait Implementations§
Source§impl Clone for TypedMetadata
impl Clone for TypedMetadata
Source§fn clone(&self) -> TypedMetadata
fn clone(&self) -> TypedMetadata
Returns a duplicate 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 TypedMetadata
impl Debug for TypedMetadata
Source§impl Default for TypedMetadata
impl Default for TypedMetadata
Source§fn default() -> TypedMetadata
fn default() -> TypedMetadata
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TypedMetadata
impl !RefUnwindSafe for TypedMetadata
impl Send for TypedMetadata
impl Sync for TypedMetadata
impl Unpin for TypedMetadata
impl UnsafeUnpin for TypedMetadata
impl !UnwindSafe for TypedMetadata
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