Skip to main content

Metadata

Struct Metadata 

Source
pub struct Metadata(/* private fields */);
Expand description

A structured, ordered, typed key-value store for metadata fields.

Metadata stores values as qubit_value::Value, preserving concrete Rust scalar types such as i64, u32, f64, String, and bool. This avoids the ambiguity of a single JSON number type while still allowing callers to store explicit Value::Json values when they really need JSON payloads.

Use Metadata::with for fluent construction and Metadata::set when mutating an existing object.

Implementations§

Source§

impl Metadata

Source

pub fn new() -> Self

Creates an empty metadata object.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no entries.

Source

pub fn len(&self) -> usize

Returns the number of key-value pairs.

Source

pub fn contains_key(&self, key: &str) -> bool

Returns true if the given key exists.

Source

pub fn get<T>(&self, key: &str) -> Option<T>

Retrieves the value associated with key and converts it to T.

This convenience method returns None when the key is absent or when the stored Value cannot be converted to T.

Source

pub fn try_get<T>(&self, key: &str) -> MetadataResult<T>

Retrieves the value associated with key and converts it to T.

§Errors

Returns MetadataError::MissingKey when the key is absent, or MetadataError::TypeMismatch when the stored value cannot be converted to the requested type.

Source

pub fn get_raw(&self, key: &str) -> Option<&Value>

Returns a reference to the stored Value for key, or None if absent.

Source

pub fn data_type(&self, key: &str) -> Option<DataType>

Returns the concrete data type of the value stored under key.

Source

pub fn get_or<T>(&self, key: &str, default: T) -> T

Retrieves and converts the value associated with key, or returns default if lookup or conversion fails.

Source

pub fn set<T>(&mut self, key: &str, value: T) -> Option<Value>

Inserts a typed value under key and returns the previous value if present.

Source

pub fn set_checked<T>( &mut self, schema: &MetadataSchema, key: &str, value: T, ) -> MetadataResult<Option<Value>>

Inserts a typed value after validating it against schema.

§Errors

Returns MetadataError::UnknownField when key is rejected by the schema, or MetadataError::TypeMismatch when the constructed value’s concrete type does not match the schema field type.

Source

pub fn with_checked<T>( self, schema: &MetadataSchema, key: &str, value: T, ) -> MetadataResult<Self>

Returns a new metadata object with a typed value validated and inserted.

§Errors

Returns MetadataError::UnknownField when key is rejected by the schema, or MetadataError::TypeMismatch when the constructed value’s concrete type does not match the schema field type.

Source

pub fn with<T>(self, key: &str, value: T) -> Self

Returns a new metadata object with key set to value.

Source

pub fn set_raw(&mut self, key: &str, value: Value) -> Option<Value>

Inserts a raw Value directly and returns the previous value if present.

Source

pub fn with_raw(self, key: &str, value: Value) -> Self

Returns a new metadata object with a raw Value inserted.

Source

pub fn remove(&mut self, key: &str) -> Option<Value>

Removes the entry for key and returns the stored Value if it existed.

Source

pub fn clear(&mut self)

Removes all entries.

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &Value)>

Returns an iterator over (&str, &Value) pairs in key-sorted order.

Source

pub fn keys(&self) -> impl Iterator<Item = &str>

Returns an iterator over the keys in sorted order.

Source

pub fn values(&self) -> impl Iterator<Item = &Value>

Returns an iterator over the values in key-sorted order.

Source

pub fn merge(&mut self, other: Metadata)

Merges all entries from other into self, overwriting existing keys.

Source

pub fn merged(&self, other: &Metadata) -> Metadata

Returns a new Metadata that contains entries from self and other.

Entries from other take precedence on key conflicts.

Source

pub fn retain<F>(&mut self, predicate: F)
where F: FnMut(&str, &Value) -> bool,

Retains only the entries for which predicate returns true.

Source

pub fn into_inner(self) -> BTreeMap<String, Value>

Converts this metadata object into its underlying map.

Trait Implementations§

Source§

impl Clone for Metadata

Source§

fn clone(&self) -> Metadata

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Metadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Metadata

Source§

fn default() -> Metadata

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Metadata

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Extend<(String, Value)> for Metadata

Source§

fn extend<I: IntoIterator<Item = (String, Value)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<BTreeMap<String, Value>> for Metadata

Source§

fn from(map: BTreeMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Metadata> for BTreeMap<String, Value>

Source§

fn from(meta: Metadata) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for Metadata

Source§

fn from_iter<I: IntoIterator<Item = (String, Value)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a Metadata

Source§

type IntoIter = Iter<'a, String, Value>

Which kind of iterator are we turning this into?
Source§

type Item = (&'a String, &'a Value)

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Metadata

Source§

type IntoIter = IntoIter<String, Value>

Which kind of iterator are we turning this into?
Source§

type Item = (String, Value)

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Metadata

Source§

fn eq(&self, other: &Metadata) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Metadata

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,