pub struct Metadata(Option<Arc<BTreeMap<String, String>>>);Expand description
A cheaply clonable map of key-value metadata, used by
Field and Schema.
Cloning a Metadata is always cheap, as the underlying map is
reference-counted. Mutating a shared Metadata (e.g. via
Metadata::insert) will clone the underlying map if (and only if)
it is shared (copy-on-write).
The entries are stored in a BTreeMap, so iteration order is
deterministic (sorted by key).
§Example
let mut metadata = Metadata::new();
metadata.insert("key", "value");
let clone = metadata.clone(); // cheap
assert_eq!(clone.get("key"), Some(&"value".to_string()));
// Mutating one does not affect the other:
metadata.insert("key2", "value2");
assert_eq!(metadata.len(), 2);
assert_eq!(clone.len(), 1);Tuple Fields§
§0: Option<Arc<BTreeMap<String, String>>>Implementations§
Source§impl Metadata
impl Metadata
Sourcepub fn get(&self, key: &str) -> Option<&String>
pub fn get(&self, key: &str) -> Option<&String>
Returns a reference to the value corresponding to the key.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Returns true if the map contains a value for the specified key.
Sourcepub fn insert(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> Option<String>
pub fn insert( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> Option<String>
Inserts a key-value pair, returning the old value of the key, if any.
If the map already contained this key, the value is replaced.
Clones the underlying map if (and only if) it is shared.
Sourcepub fn with(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with(self, key: impl Into<String>, value: impl Into<String>) -> Self
Inserts a key-value pair and returns self, for builder-style chaining.
If the map already contained this key, the value is replaced.
§Example
let metadata = Metadata::new().with("a", "1").with("b", "2");
assert_eq!(metadata.len(), 2);Sourcepub fn remove(&mut self, key: &str) -> Option<String>
pub fn remove(&mut self, key: &str) -> Option<String>
Removes a key from the map, returning the value at the key if the key was previously in the map.
Clones the underlying map if (and only if) it is shared and contains the key.
Sourcepub fn iter(&self) -> MetadataIter<'_>
pub fn iter(&self) -> MetadataIter<'_>
Returns an iterator over the entries, sorted by key.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Metadata
impl<'de> Deserialize<'de> for Metadata
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Metadata
Source§impl<K: Into<String>, V: Into<String>> Extend<(K, V)> for Metadata
impl<K: Into<String>, V: Into<String>> Extend<(K, V)> for Metadata
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)