MetadataMap

Struct MetadataMap 

pub struct MetadataMap { /* private fields */ }
Expand description

A set of gRPC custom metadata entries.

Implementations§

§

impl MetadataMap

pub fn new() -> MetadataMap

Create an empty MetadataMap.

The map will be created without any capacity. This function will not allocate.

pub fn from_headers(headers: HeaderMap) -> MetadataMap

Convert an HTTP HeaderMap to a MetadataMap

pub fn into_headers(self) -> HeaderMap

Convert a MetadataMap into a HTTP HeaderMap

pub fn with_capacity(capacity: usize) -> MetadataMap

Create an empty MetadataMap with the specified capacity.

The returned map will allocate internal storage in order to hold about capacity elements without reallocating. However, this is a “best effort” as there are usage patterns that could cause additional allocations before capacity metadata entries are stored in the map.

More capacity than requested may be allocated.

pub fn len(&self) -> usize

Returns the number of metadata entries (ascii and binary) stored in the map.

This number represents the total number of values stored in the map. This number can be greater than or equal to the number of keys stored given that a single key may have more than one associated value.

pub fn keys_len(&self) -> usize

Returns the number of keys (ascii and binary) stored in the map.

This number will be less than or equal to len() as each key may have more than one associated value.

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

pub fn clear(&mut self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

pub fn capacity(&self) -> usize

Returns the number of custom metadata entries the map can hold without reallocating.

This number is an approximation as certain usage patterns could cause additional allocations before the returned capacity is filled.

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more custom metadata to be inserted into the MetadataMap.

The metadata map may reserve more space to avoid frequent reallocations. Like with with_capacity, this will be a “best effort” to avoid allocations until additional more custom metadata is inserted. Certain usage patterns could cause additional allocations before the number is reached.

§Panics

Panics if the new allocation size overflows usize.

pub fn get<K>(&self, key: K) -> Option<&MetadataValue<Ascii>>
where K: AsMetadataKey<Ascii>,

Returns a reference to the value associated with the key. This method is for ascii metadata entries (those whose names don’t end with “-bin”). For binary entries, use get_bin.

If there are multiple values associated with the key, then the first one is returned. Use get_all to get all values associated with a given key. Returns None if there are no values associated with the key.

pub fn get_bin<K>(&self, key: K) -> Option<&MetadataValue<Binary>>
where K: AsMetadataKey<Binary>,

Like get, but for Binary keys (for example “trace-proto-bin”).

pub fn get_mut<K>(&mut self, key: K) -> Option<&mut MetadataValue<Ascii>>
where K: AsMetadataKey<Ascii>,

Returns a mutable reference to the value associated with the key. This method is for ascii metadata entries (those whose names don’t end with “-bin”). For binary entries, use get_mut_bin.

If there are multiple values associated with the key, then the first one is returned. Use entry to get all values associated with a given key. Returns None if there are no values associated with the key.

pub fn get_bin_mut<K>(&mut self, key: K) -> Option<&mut MetadataValue<Binary>>
where K: AsMetadataKey<Binary>,

Like get_mut, but for Binary keys (for example “trace-proto-bin”).

pub fn get_all<K>(&self, key: K) -> GetAll<'_, Ascii>
where K: AsMetadataKey<Ascii>,

Returns a view of all values associated with a key. This method is for ascii metadata entries (those whose names don’t end with “-bin”). For binary entries, use get_all_bin.

The returned view does not incur any allocations and allows iterating the values associated with the key. See GetAll for more details. Returns None if there are no values associated with the key.

pub fn get_all_bin<K>(&self, key: K) -> GetAll<'_, Binary>
where K: AsMetadataKey<Binary>,

Like get_all, but for Binary keys (for example “trace-proto-bin”).

pub fn contains_key<K>(&self, key: &K) -> bool
where K: AsEncodingAgnosticMetadataKey,

Returns true if the map contains a value for the specified key. This method works for both ascii and binary entries.

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

An iterator visiting all key-value pairs (both ascii and binary).

The iteration order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded once per associated value. So, if a key has 3 associated values, it will be yielded 3 times.

pub fn iter_mut(&mut self) -> IterMut<'_>

An iterator visiting all key-value pairs, with mutable value references.

The iterator order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded once per associated value, so if a key has 3 associated values, it will be yielded 3 times.

pub fn keys(&self) -> Keys<'_>

An iterator visiting all keys.

The iteration order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded only once even if it has multiple associated values.

pub fn values(&self) -> Values<'_>

An iterator visiting all values (both ascii and binary).

The iteration order is arbitrary, but consistent across platforms for the same crate version.

pub fn values_mut(&mut self) -> ValuesMut<'_>

An iterator visiting all values mutably.

The iteration order is arbitrary, but consistent across platforms for the same crate version.

pub fn entry<K>( &mut self, key: K, ) -> Result<Entry<'_, Ascii>, InvalidMetadataKey>
where K: AsMetadataKey<Ascii>,

Gets the given ascii key’s corresponding entry in the map for in-place manipulation. For binary keys, use entry_bin.

pub fn entry_bin<K>( &mut self, key: K, ) -> Result<Entry<'_, Binary>, InvalidMetadataKey>
where K: AsMetadataKey<Binary>,

Gets the given Binary key’s corresponding entry in the map for in-place manipulation.

pub fn insert<K>( &mut self, key: K, val: MetadataValue<Ascii>, ) -> Option<MetadataValue<Ascii>>
where K: IntoMetadataKey<Ascii>,

Inserts an ascii key-value pair into the map. To insert a binary entry, use insert_bin.

This method panics when the given key is a string and it cannot be converted to a MetadataKey<Ascii>.

If the map did not previously have this key present, then None is returned.

If the map did have this key present, the new value is associated with the key and all previous values are removed. Note that only a single one of the previous values is returned. If there are multiple values that have been previously associated with the key, then the first one is returned. See insert_mult on OccupiedEntry for an API that returns all values.

The key is not updated, though; this matters for types that can be == without being identical.

pub fn insert_bin<K>( &mut self, key: K, val: MetadataValue<Binary>, ) -> Option<MetadataValue<Binary>>
where K: IntoMetadataKey<Binary>,

Like insert, but for Binary keys (for example “trace-proto-bin”).

This method panics when the given key is a string and it cannot be converted to a MetadataKey<Binary>.

pub fn append<K>(&mut self, key: K, value: MetadataValue<Ascii>) -> bool
where K: IntoMetadataKey<Ascii>,

Inserts an ascii key-value pair into the map. To insert a binary entry, use append_bin.

This method panics when the given key is a string and it cannot be converted to a MetadataKey<Ascii>.

If the map did not previously have this key present, then false is returned.

If the map did have this key present, the new value is pushed to the end of the list of values currently associated with the key. The key is not updated, though; this matters for types that can be == without being identical.

pub fn append_bin<K>(&mut self, key: K, value: MetadataValue<Binary>) -> bool
where K: IntoMetadataKey<Binary>,

Like append, but for binary keys (for example “trace-proto-bin”).

This method panics when the given key is a string and it cannot be converted to a MetadataKey<Binary>.

pub fn remove<K>(&mut self, key: K) -> Option<MetadataValue<Ascii>>
where K: AsMetadataKey<Ascii>,

Removes an ascii key from the map, returning the value associated with the key. To remove a binary key, use remove_bin.

Returns None if the map does not contain the key. If there are multiple values associated with the key, then the first one is returned. See remove_entry_mult on OccupiedEntry for an API that yields all values.

pub fn remove_bin<K>(&mut self, key: K) -> Option<MetadataValue<Binary>>
where K: AsMetadataKey<Binary>,

Like remove, but for Binary keys (for example “trace-proto-bin”).

Trait Implementations§

§

impl AsMut<HeaderMap> for MetadataMap

§

fn as_mut(&mut self) -> &mut HeaderMap

Converts this type into a mutable reference of the (usually inferred) input type.
§

impl AsRef<HeaderMap> for MetadataMap

§

fn as_ref(&self) -> &HeaderMap

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Clone for MetadataMap

§

fn clone(&self) -> MetadataMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for MetadataMap

§

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

Formats the value using the given formatter. Read more
§

impl Default for MetadataMap

§

fn default() -> MetadataMap

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

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a rama_grpc::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> RamaFrom<T> for U
where U: From<T>,

§

fn rama_from(value: T) -> U

§

impl<T, U, CrateMarker> RamaInto<U, CrateMarker> for T
where U: RamaFrom<T, CrateMarker>,

§

fn rama_into(self) -> U

§

impl<T, U> RamaTryFrom<T> for U
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

§

fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>

§

impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for T
where U: RamaTryFrom<T, CrateMarker>,

§

type Error = <U as RamaTryFrom<T, CrateMarker>>::Error

§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more