Struct Metadata
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§
§impl Metadata
impl Metadata
pub 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.
pub 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.
pub 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.
pub fn with(self, key: impl Into<String>, value: impl Into<String>) -> Metadata
pub fn with(self, key: impl Into<String>, value: impl Into<String>) -> Metadata
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);pub 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.
pub fn clear(&mut self)
pub fn clear(&mut self)
Removes all entries.
pub fn iter(&self) -> Flatten<IntoIter<Iter<'_, String, String>>> ⓘ
pub fn iter(&self) -> Flatten<IntoIter<Iter<'_, String, String>>> ⓘ
Returns an iterator over the entries, sorted by key.
Trait Implementations§
§impl<'de> Deserialize<'de> for Metadata
impl<'de> Deserialize<'de> for Metadata
§fn deserialize<D>(
deserializer: D,
) -> Result<Metadata, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Metadata, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for Metadata
§impl<K, V> Extend<(K, V)> for Metadata
impl<K, V> Extend<(K, V)> for Metadata
§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
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)§impl<K, V> FromIterator<(K, V)> for Metadata
impl<K, V> FromIterator<(K, V)> for Metadata
§impl<'a> IntoIterator for &'a Metadata
impl<'a> IntoIterator for &'a Metadata
§impl IntoIterator for Metadata
impl IntoIterator for Metadata
§impl Ord for Metadata
impl Ord for Metadata
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialOrd for Metadata
impl PartialOrd for Metadata
§impl Serialize for Metadata
impl Serialize for Metadata
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
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§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<'py, T, I> IntoPyDict<'py> for Iwhere
T: PyDictItem<'py>,
I: IntoIterator<Item = T>,
impl<'py, T, I> IntoPyDict<'py> for Iwhere
T: PyDictItem<'py>,
I: IntoIterator<Item = T>,
§fn into_py_dict(self, py: Python<'py>) -> Result<Bound<'py, PyDict>, PyErr>
fn into_py_dict(self, py: Python<'py>) -> Result<Bound<'py, PyDict>, PyErr>
PyDict object pointer. Whether pointer owned or borrowed
depends on implementation.