Struct tonic::metadata::MetadataKey

source ·
pub struct MetadataKey<VE: ValueEncoding> { /* private fields */ }
Expand description

Represents a custom metadata field name.

MetadataKey is used as the MetadataMap key.

Implementations§

source§

impl<VE: ValueEncoding> MetadataKey<VE>

source

pub fn from_bytes(src: &[u8]) -> Result<Self, InvalidMetadataKey>

Converts a slice of bytes to a MetadataKey.

This function normalizes the input.

source

pub fn from_static(src: &'static str) -> Self

Converts a static string to a MetadataKey.

This function panics when the static string is a invalid metadata key.

This function requires the static string to only contain lowercase characters, numerals and symbols, as per the HTTP/2.0 specification and header names internal representation within this library.

§Examples
// Parsing a metadata key
let CUSTOM_KEY: &'static str = "custom-key";

let a = AsciiMetadataKey::from_bytes(b"custom-key").unwrap();
let b = AsciiMetadataKey::from_static(CUSTOM_KEY);
assert_eq!(a, b);
// Parsing a metadata key that contains invalid symbols(s):
AsciiMetadataKey::from_static("content{}{}length"); // This line panics!
// Parsing a metadata key that contains invalid uppercase characters.
let a = AsciiMetadataKey::from_static("foobar");
let b = AsciiMetadataKey::from_static("FOOBAR"); // This line panics!
// Parsing a -bin metadata key as an Ascii key.
let b = AsciiMetadataKey::from_static("hello-bin"); // This line panics!
// Parsing a non-bin metadata key as an Binary key.
let b = BinaryMetadataKey::from_static("hello"); // This line panics!
source

pub fn as_str(&self) -> &str

Returns a str representation of the metadata key.

The returned string will always be lower case.

Trait Implementations§

source§

impl<VE: ValueEncoding> AsRef<[u8]> for MetadataKey<VE>

source§

fn as_ref(&self) -> &[u8]

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

impl<VE: ValueEncoding> AsRef<str> for MetadataKey<VE>

source§

fn as_ref(&self) -> &str

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

impl<VE: ValueEncoding> Borrow<str> for MetadataKey<VE>

source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
source§

impl<VE: Clone + ValueEncoding> Clone for MetadataKey<VE>

source§

fn clone(&self) -> MetadataKey<VE>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<VE: ValueEncoding> Debug for MetadataKey<VE>

source§

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

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

impl<VE: ValueEncoding> Display for MetadataKey<VE>

source§

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

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

impl<'a, VE: ValueEncoding> From<&'a MetadataKey<VE>> for MetadataKey<VE>

source§

fn from(src: &'a MetadataKey<VE>) -> MetadataKey<VE>

Converts to this type from the input type.
source§

impl<KeyVE: ValueEncoding> From<MetadataKey<KeyVE>> for MetadataValue<Ascii>

source§

fn from(h: MetadataKey<KeyVE>) -> MetadataValue<Ascii>

Converts to this type from the input type.
source§

impl<VE: ValueEncoding> From<MetadataKey<VE>> for Bytes

source§

fn from(name: MetadataKey<VE>) -> Bytes

Converts to this type from the input type.
source§

impl<VE: ValueEncoding> FromStr for MetadataKey<VE>

§

type Err = InvalidMetadataKey

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, InvalidMetadataKey>

Parses a string s to return a value of this type. Read more
source§

impl<VE: Hash + ValueEncoding> Hash for MetadataKey<VE>

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<'a, VE: ValueEncoding> PartialEq<&'a MetadataKey<VE>> for MetadataKey<VE>

source§

fn eq(&self, other: &&'a MetadataKey<VE>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, VE: ValueEncoding> PartialEq<&'a str> for MetadataKey<VE>

source§

fn eq(&self, other: &&'a str) -> bool

Performs a case-insensitive comparison of the string against the header name

1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, VE: ValueEncoding> PartialEq<MetadataKey<VE>> for &'a MetadataKey<VE>

source§

fn eq(&self, other: &MetadataKey<VE>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, VE: ValueEncoding> PartialEq<MetadataKey<VE>> for &'a str

source§

fn eq(&self, other: &MetadataKey<VE>) -> bool

Performs a case-insensitive comparison of the string against the header name

1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<VE: ValueEncoding> PartialEq<MetadataKey<VE>> for str

source§

fn eq(&self, other: &MetadataKey<VE>) -> bool

Performs a case-insensitive comparison of the string against the header name

§Examples
let content_length = AsciiMetadataKey::from_static("content-length");

assert_eq!(content_length, "content-length");
assert_eq!(content_length, "Content-Length");
assert_ne!(content_length, "content length");
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<VE: ValueEncoding> PartialEq<str> for MetadataKey<VE>

source§

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

Performs a case-insensitive comparison of the string against the header name

§Examples
let content_length = AsciiMetadataKey::from_static("content-length");

assert_eq!(content_length, "content-length");
assert_eq!(content_length, "Content-Length");
assert_ne!(content_length, "content length");
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<VE: PartialEq + ValueEncoding> PartialEq for MetadataKey<VE>

source§

fn eq(&self, other: &MetadataKey<VE>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<VE: Eq + ValueEncoding> Eq for MetadataKey<VE>

source§

impl<VE: ValueEncoding> StructuralPartialEq for MetadataKey<VE>

Auto Trait Implementations§

§

impl<VE> RefUnwindSafe for MetadataKey<VE>
where VE: RefUnwindSafe,

§

impl<VE> Send for MetadataKey<VE>
where VE: Send,

§

impl<VE> Sync for MetadataKey<VE>
where VE: Sync,

§

impl<VE> Unpin for MetadataKey<VE>
where VE: Unpin,

§

impl<VE> UnwindSafe for MetadataKey<VE>
where VE: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

Compare self to key and return true if they are equal.
source§

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

source§

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

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

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

source§

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> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

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

impl<T> Instrument for T

source§

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

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

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

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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