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
impl Metadata
Sourcepub fn get(&self, key: &str) -> Option<&MetadataValue>
pub fn get(&self, key: &str) -> Option<&MetadataValue>
Returns the value associated with key.
Sourcepub fn insert(
&mut self,
key: String,
value: MetadataValue,
) -> Option<MetadataValue>
pub fn insert( &mut self, key: String, value: MetadataValue, ) -> Option<MetadataValue>
Associates value with key, returning whatever key already held.
Sourcepub fn iter(&self) -> MetadataIter<'_> ⓘ
pub fn iter(&self) -> MetadataIter<'_> ⓘ
Iterates over entries in ascending key order.
Trait Implementations§
Source§impl Debug for Metadata
impl Debug for Metadata
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
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
impl<'de> Deserialize<'de> for Metadata
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl FromIterator<(String, MetadataValue)> for Metadata
impl FromIterator<(String, MetadataValue)> for Metadata
Source§fn from_iter<I: IntoIterator<Item = (String, MetadataValue)>>(
entries: I,
) -> Self
fn from_iter<I: IntoIterator<Item = (String, MetadataValue)>>( entries: I, ) -> Self
Collects entries; a repeated key keeps the last value supplied.