[][src]Struct tonic::metadata::MetadataKey

#[repr(transparent)]pub struct MetadataKey<VE: ValueEncoding> { /* fields omitted */ }

Represents a custom metadata field name.

MetadataKey is used as the MetadataMap key.

Methods

impl<VE: ValueEncoding> MetadataKey<VE>[src]

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

Converts a slice of bytes to a MetadataKey.

This function normalizes the input.

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

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!

pub fn as_str(&self) -> &str[src]

Returns a str representation of the metadata key.

The returned string will always be lower case.

Trait Implementations

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

impl<VE: ValueEncoding> AsRef<str> for MetadataKey<VE>[src]

impl<VE: ValueEncoding> Borrow<str> for MetadataKey<VE>[src]

impl<VE: Clone + ValueEncoding> Clone for MetadataKey<VE>[src]

impl<VE: ValueEncoding> Debug for MetadataKey<VE>[src]

impl<VE: ValueEncoding> Display for MetadataKey<VE>[src]

impl<VE: Eq + ValueEncoding> Eq for MetadataKey<VE>[src]

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

impl<KeyVE: ValueEncoding> From<MetadataKey<KeyVE>> for MetadataValue<Ascii>[src]

impl<VE: ValueEncoding> From<MetadataKey<VE>> for Bytes[src]

impl<VE: ValueEncoding> FromStr for MetadataKey<VE>[src]

type Err = InvalidMetadataKey

The associated error which can be returned from parsing.

impl<VE: Hash + ValueEncoding> Hash for MetadataKey<VE>[src]

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

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

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

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

impl<VE: PartialEq + ValueEncoding> PartialEq<MetadataKey<VE>> for MetadataKey<VE>[src]

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

impl<VE: ValueEncoding> PartialEq<MetadataKey<VE>> for str[src]

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

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

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

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

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

impl<VE: ValueEncoding> PartialEq<str> for MetadataKey<VE>[src]

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

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

impl<VE: ValueEncoding> StructuralEq for MetadataKey<VE>[src]

impl<VE: ValueEncoding> StructuralPartialEq for MetadataKey<VE>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

impl<T> WithSubscriber for T[src]