Skip to main content

Metadata

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

pub const fn new() -> Metadata

Creates an empty Metadata.

This does not allocate.

pub fn len(&self) -> usize

Returns the number of entries.

pub fn is_empty(&self) -> bool

Returns true if there are no entries.

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

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>

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

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>

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)

Removes all entries.

pub fn iter(&self) -> Flatten<IntoIter<Iter<'_, String, String>>>

Returns an iterator over the entries, sorted by key.

pub fn keys(&self) -> impl Iterator<Item = &String>

Returns an iterator over the keys, in sorted order.

pub fn values(&self) -> impl Iterator<Item = &String>

Returns an iterator over the values, sorted by key.

Trait Implementations§

§

impl Clone for Metadata

§

fn clone(&self) -> Metadata

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
§

impl Debug for Metadata

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Metadata

§

fn default() -> Metadata

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for Metadata

§

fn deserialize<D>( deserializer: D, ) -> Result<Metadata, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Eq for Metadata

§

impl<K, V> Extend<(K, V)> for Metadata
where K: Into<String>, V: Into<String>,

§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = (K, V)>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
§

impl From<Arc<BTreeMap<String, String>>> for Metadata

§

fn from(map: Arc<BTreeMap<String, String>>) -> Metadata

Converts to this type from the input type.
§

impl From<BTreeMap<String, String>> for Metadata

§

fn from(map: BTreeMap<String, String>) -> Metadata

Converts to this type from the input type.
§

impl From<HashMap<String, String>> for Metadata

§

fn from(map: HashMap<String, String>) -> Metadata

Converts to this type from the input type.
§

impl<K, V, const N: usize> From<[(K, V); N]> for Metadata
where K: Into<String>, V: Into<String>,

§

fn from(entries: [(K, V); N]) -> Metadata

Converts to this type from the input type.
§

impl<K, V> FromIterator<(K, V)> for Metadata
where K: Into<String>, V: Into<String>,

§

fn from_iter<T>(iter: T) -> Metadata
where T: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
§

impl Hash for Metadata

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl Index<&str> for Metadata

§

type Output = String

The returned type after indexing.
§

fn index(&self, key: &str) -> &String

Performs the indexing (container[index]) operation. Read more
§

impl<'a> IntoIterator for &'a Metadata

§

type Item = (&'a String, &'a String)

The type of the elements being iterated over.
§

type IntoIter = Flatten<IntoIter<Iter<'a, String, String>>>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <&'a Metadata as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl IntoIterator for Metadata

§

type Item = (String, String)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<String, String>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <Metadata as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl Ord for Metadata

§

fn cmp(&self, other: &Metadata) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl PartialEq for Metadata

§

fn eq(&self, other: &Metadata) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl PartialEq<BTreeMap<String, String>> for Metadata

§

fn eq(&self, other: &BTreeMap<String, String>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl PartialEq<HashMap<String, String>> for Metadata

§

fn eq(&self, other: &HashMap<String, String>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl PartialOrd for Metadata

§

fn partial_cmp(&self, other: &Metadata) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl Serialize for Metadata

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<'py, T, I> IntoPyDict<'py> for I
where T: PyDictItem<'py>, I: IntoIterator<Item = T>,

§

fn into_py_dict(self, py: Python<'py>) -> Result<Bound<'py, PyDict>, PyErr>

Converts self into a PyDict object pointer. Whether pointer owned or borrowed depends on implementation.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> Ungil for T
where T: Send,