Skip to main content

Metadata

Struct Metadata 

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

An owned, callback-free metadata object.

§Ordering

Iteration — through Metadata::iter or IntoIterator — yields entries in ascending key order. This is a guarantee, not an artefact of the current storage: ADR-004’s determinism for wire codecs depends on it, so a later storage change has to preserve it.

use reef_core::value::content;
let values = vec![
    content::MetadataValue::Null, content::MetadataValue::Bool(true), content::MetadataValue::Signed(-1),
    content::MetadataValue::Unsigned(1), content::MetadataValue::Float(1.5),
    content::MetadataValue::String("text".into()), content::MetadataValue::Bytes(vec![1].into_boxed_slice()),
    content::MetadataValue::Array(vec![]), content::MetadataValue::Object(content::Metadata::new()),
];
let mut metadata = content::Metadata::new();
metadata.insert("values".into(), content::MetadataValue::Array(values));
assert!(matches!(metadata.get("values"), Some(content::MetadataValue::Array(values)) if values.len() == 9));
assert_eq!(metadata.iter().len(), 1);
assert_eq!(metadata.into_iter().count(), 1);
ⓘ
use reef_core::value::content;
let callback = Box::new(|| {});
let _invalid = content::Metadata::from_iter([("callback".to_owned(), callback)]);

Implementations§

Source§

impl Metadata

Source

pub const fn new() -> Self

Creates an empty, present metadata object.

Source

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

Returns the value associated with key.

Source

pub fn insert( &mut self, key: String, value: MetadataValue, ) -> Option<MetadataValue>

Associates value with key, returning whatever key already held.

Source

pub fn iter(&self) -> MetadataIter<'_> ⓘ

Iterates over entries in ascending key order.

Trait Implementations§

Source§

impl Clone for Metadata

Source§

fn clone(&self) -> Self

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, formatter: &mut Formatter<'_>) -> Result

States how many entries exist and stops there.

Not iterating is what makes this implementation safe as well as discreet: keys and values are model-visible, and a MetadataValue tree nests without any depth limit, so a formatter that descended would overflow the stack on the same values Clone and Drop already survive iteratively.

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 FromIterator<(String, MetadataValue)> for Metadata

Source§

fn from_iter<I: IntoIterator<Item = (String, MetadataValue)>>( entries: I, ) -> Self

Collects entries; a repeated key keeps the last value supplied.

Source§

impl IntoIterator for Metadata

Source§

fn into_iter(self) -> Self::IntoIter

Transfers every entry in ascending key order.

Source§

type Item = (String, MetadataValue)

The type of the elements being iterated over.
Source§

type IntoIter = MetadataIntoIter

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

impl<'a> IntoIterator for &'a Metadata

Source§

type Item = (&'a str, &'a MetadataValue)

The type of the elements being iterated over.
Source§

type IntoIter = MetadataIter<'a>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
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

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.