pub struct Metadata(/* private fields */);Expand description
An immutable, ordered map of metadata keys to Values.
Build one from a BTreeMap with From, or collect it from an iterator
of (String, Value) pairs. Read it with get,
len, is_empty, and
iter. There are no setters — to change metadata, build a
new value.
§Examples
use iqdb_types::{Metadata, Value};
let meta: Metadata = [
("title".to_string(), Value::String("intro".to_string())),
("year".to_string(), Value::Int(2026)),
]
.into_iter()
.collect();
assert_eq!(meta.len(), 2);
assert_eq!(meta.get("year"), Some(&Value::Int(2026)));
assert_eq!(meta.get("missing"), None);Implementations§
Source§impl Metadata
impl Metadata
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Returns the value for key, or None if the key is absent.
§Examples
use iqdb_types::{Metadata, Value};
let meta: Metadata =
[("year".to_string(), Value::Int(2026))].into_iter().collect();
assert_eq!(meta.get("year"), Some(&Value::Int(2026)));
assert_eq!(meta.get("nope"), None);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of entries.
§Examples
use iqdb_types::{Metadata, Value};
let meta: Metadata =
[("a".to_string(), Value::Null)].into_iter().collect();
assert_eq!(meta.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no entries.
§Examples
use iqdb_types::Metadata;
assert!(Metadata::default().is_empty());Sourcepub fn iter(&self) -> Iter<'_, String, Value>
pub fn iter(&self) -> Iter<'_, String, Value>
Returns an iterator over the entries in key order.
§Examples
use iqdb_types::{Metadata, Value};
let meta: Metadata = [
("b".to_string(), Value::Int(2)),
("a".to_string(), Value::Int(1)),
]
.into_iter()
.collect();
// BTreeMap iterates in key order.
let keys: Vec<&String> = meta.iter().map(|(key, _)| key).collect();
assert_eq!(keys, vec!["a", "b"]);Trait Implementations§
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>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Metadata
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnsafeUnpin for Metadata
impl UnwindSafe for Metadata
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