Skip to main content

Metadata

Struct Metadata 

Source
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

Source

pub const fn new() -> Self

Creates an empty Metadata.

This does not allocate.

Source

pub fn len(&self) -> usize

Returns the number of entries.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no entries.

Source

pub fn get(&self, key: &str) -> Option<&String>

Returns a reference to the value corresponding to the key.

Source

pub fn contains_key(&self, key: &str) -> bool

Returns true if the map contains a value for the specified key.

Source

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.

Source

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);
Source

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.

Source

pub fn clear(&mut self)

Removes all entries.

Source

pub fn iter(&self) -> MetadataIter<'_>

Returns an iterator over the entries, sorted by key.

Source

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

Returns an iterator over the keys, in sorted order.

Source

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

Returns an iterator over the values, sorted by key.

Trait Implementations§

Source§

impl Clone for Metadata

Source§

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

impl Debug for Metadata

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Metadata

Source§

fn default() -> Metadata

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

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

Source§

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

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

impl Eq for Metadata

Source§

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

Source§

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

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

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

Source§

fn from(metadata: &Metadata) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from(metadata: Metadata) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(metadata: Metadata) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Creates a value from an iterator. Read more
Source§

impl Hash for Metadata

Source§

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

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

impl Index<&str> for Metadata

Source§

type Output = String

The returned type after indexing.
Source§

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

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

impl<'a> IntoIterator for &'a Metadata

Source§

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

The type of the elements being iterated over.
Source§

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

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Metadata

Source§

type Item = (String, String)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String, String>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for Metadata

Source§

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

impl PartialEq for Metadata

Source§

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

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

Source§

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

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

Source§

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

impl PartialOrd for Metadata

Source§

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

impl Serialize for Metadata

Source§

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

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

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

Blanket Implementations§

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

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

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.

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.