Struct MetadataMap
pub struct MetadataMap { /* private fields */ }Expand description
A set of gRPC custom metadata entries.
Implementations§
§impl MetadataMap
impl MetadataMap
pub fn new() -> 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
pub fn from_headers(headers: HeaderMap) -> MetadataMap
Convert an HTTP HeaderMap to a MetadataMap
pub fn into_headers(self) -> HeaderMap
pub fn into_headers(self) -> HeaderMap
Convert a MetadataMap into a HTTP HeaderMap
pub fn with_capacity(capacity: usize) -> MetadataMap
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
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
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 clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
pub fn capacity(&self) -> usize
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)
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>,
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>,
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>,
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>,
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>,
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>,
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) -> boolwhere
K: AsEncodingAgnosticMetadataKey,
pub fn contains_key<K>(&self, key: &K) -> boolwhere
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<'_> ⓘ
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<'_> ⓘ
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<'_> ⓘ
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<'_> ⓘ
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<'_> ⓘ
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>,
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>,
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>,
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>,
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>) -> boolwhere
K: IntoMetadataKey<Ascii>,
pub fn append<K>(&mut self, key: K, value: MetadataValue<Ascii>) -> boolwhere
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>) -> boolwhere
K: IntoMetadataKey<Binary>,
pub fn append_bin<K>(&mut self, key: K, value: MetadataValue<Binary>) -> boolwhere
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>,
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>,
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
impl AsMut<HeaderMap> for MetadataMap
§impl AsRef<HeaderMap> for MetadataMap
impl AsRef<HeaderMap> for MetadataMap
§impl Clone for MetadataMap
impl Clone for MetadataMap
§fn clone(&self) -> MetadataMap
fn clone(&self) -> MetadataMap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for MetadataMap
impl Debug for MetadataMap
§impl Default for MetadataMap
impl Default for MetadataMap
§fn default() -> MetadataMap
fn default() -> MetadataMap
Auto Trait Implementations§
impl Freeze for MetadataMap
impl RefUnwindSafe for MetadataMap
impl Send for MetadataMap
impl Sync for MetadataMap
impl Unpin for MetadataMap
impl UnwindSafe for MetadataMap
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more