[−][src]Struct tower_grpc::metadata::MetadataValue
Represents a custom metadata field value.
MetadataValue
is used as the [MetadataMap
] value.
Methods
impl<VE: ValueEncoding> MetadataValue<VE>
[src]
pub fn from_static(src: &'static str) -> Self
[src]
Convert a static string to a MetadataValue
.
This function will not perform any copying, however the string is checked to ensure that no invalid characters are present.
For Ascii values, only visible ASCII characters (32-127) are permitted. For Binary values, the string must be valid base64.
Panics
This function panics if the argument contains invalid metadata value characters.
Examples
let val = AsciiMetadataValue::from_static("hello"); assert_eq!(val, "hello");
let val = BinaryMetadataValue::from_static("SGVsbG8hIQ=="); assert_eq!(val, "Hello!!");
pub fn try_from_bytes(src: &[u8]) -> Result<Self, InvalidMetadataValueBytes>
[src]
Attempt to convert a byte slice to a MetadataValue
.
For Ascii metadata values, If the argument contains invalid metadata value bytes, an error is returned. Only byte values between 32 and 255 (inclusive) are permitted, excluding byte 127 (DEL).
For Binary metadata values this method cannot fail. See also the Binary
only version of this method from_bytes
.
This function is intended to be replaced in the future by a TryFrom
implementation once the trait is stabilized in std.
Examples
let val = AsciiMetadataValue::try_from_bytes(b"hello\xfa").unwrap(); assert_eq!(val, &b"hello\xfa"[..]);
An invalid value
let val = AsciiMetadataValue::try_from_bytes(b"\n"); assert!(val.is_err());
pub fn from_shared(src: Bytes) -> Result<Self, InvalidMetadataValueBytes>
[src]
Attempt to convert a Bytes
buffer to a MetadataValue
.
For MetadataValue<Ascii>
, if the argument contains invalid metadata
value bytes, an error is returned. Only byte values between 32 and 255
(inclusive) are permitted, excluding byte 127 (DEL).
For MetadataValue<Binary>
, if the argument is not valid base64, an
error is returned. In use cases where the input is not base64 encoded,
use from_bytes
; if the value has to be encoded it's not possible to
share the memory anyways.
This function is intended to be replaced in the future by a TryFrom
implementation once the trait is stabilized in std.
pub unsafe fn from_shared_unchecked(src: Bytes) -> Self
[src]
Convert a Bytes
directly into a MetadataValue
without validating.
For MetadataValue
This function does NOT validate that illegal bytes are not contained within the buffer.
pub fn is_empty(&self) -> bool
[src]
Returns true if the MetadataValue
has a length of zero bytes.
Examples
let val = AsciiMetadataValue::from_static(""); assert!(val.is_empty()); let val = AsciiMetadataValue::from_static("hello"); assert!(!val.is_empty());
pub fn to_bytes(&self) -> Result<Bytes, InvalidMetadataValueBytes>
[src]
Converts a MetadataValue
to a Bytes buffer. This method cannot
fail for Ascii values. For Ascii values, as_bytes
is more convenient
to use.
Examples
let val = AsciiMetadataValue::from_static("hello"); assert_eq!(val.to_bytes().unwrap().as_ref(), b"hello");
let val = BinaryMetadataValue::from_bytes(b"hello"); assert_eq!(val.to_bytes().unwrap().as_ref(), b"hello");
pub fn set_sensitive(&mut self, val: bool)
[src]
Mark that the metadata value represents sensitive information.
Examples
let mut val = AsciiMetadataValue::from_static("my secret"); val.set_sensitive(true); assert!(val.is_sensitive()); val.set_sensitive(false); assert!(!val.is_sensitive());
pub fn is_sensitive(&self) -> bool
[src]
Returns true
if the value represents sensitive data.
Sensitive data could represent passwords or other data that should not
be stored on disk or in memory. This setting can be used by components
like caches to avoid storing the value. HPACK encoders must set the
metadata field to never index when is_sensitive
returns true.
Note that sensitivity is not factored into equality or ordering.
Examples
let mut val = AsciiMetadataValue::from_static("my secret"); val.set_sensitive(true); assert!(val.is_sensitive()); val.set_sensitive(false); assert!(!val.is_sensitive());
pub fn as_encoded_bytes(&self) -> &[u8]
[src]
Converts a MetadataValue
to a byte slice. For Binary values, the
return value is base64 encoded.
Examples
let val = AsciiMetadataValue::from_static("hello"); assert_eq!(val.as_encoded_bytes(), b"hello");
let val = BinaryMetadataValue::from_bytes(b"Hello!"); assert_eq!(val.as_encoded_bytes(), b"SGVsbG8h");
impl MetadataValue<Ascii>
[src]
pub fn from_str(src: &str) -> Result<Self, InvalidMetadataValue>
[src]
Attempt to convert a string to a MetadataValue<Ascii>
.
If the argument contains invalid metadata value characters, an error is
returned. Only visible ASCII characters (32-127) are permitted. Use
from_bytes
to create a MetadataValue
that includes opaque octets
(128-255).
This function is intended to be replaced in the future by a TryFrom
implementation once the trait is stabilized in std.
Examples
let val = AsciiMetadataValue::from_str("hello").unwrap(); assert_eq!(val, "hello");
An invalid value
let val = AsciiMetadataValue::from_str("\n"); assert!(val.is_err());
pub fn from_key<KeyVE: ValueEncoding>(key: MetadataKey<KeyVE>) -> Self
[src]
Converts a MetadataKey into a MetadataValue
Since every valid MetadataKey is a valid MetadataValue this is done infallibly.
Examples
let val = AsciiMetadataValue::from_key::<Ascii>("accept".parse().unwrap()); assert_eq!(val, AsciiMetadataValue::try_from_bytes(b"accept").unwrap());
pub fn len(&self) -> usize
[src]
Returns the length of self
, in bytes.
This method is not available for MetadataValue
Examples
let val = AsciiMetadataValue::from_static("hello"); assert_eq!(val.len(), 5);
pub fn to_str(&self) -> Result<&str, ToStrError>
[src]
Yields a &str
slice if the MetadataValue
only contains visible ASCII
chars.
This function will perform a scan of the metadata value, checking all the characters.
Examples
let val = AsciiMetadataValue::from_static("hello"); assert_eq!(val.to_str().unwrap(), "hello");
pub fn as_bytes(&self) -> &[u8]
[src]
Converts a MetadataValue
to a byte slice. For Binary values, use
to_bytes
.
Examples
let val = AsciiMetadataValue::from_static("hello"); assert_eq!(val.as_bytes(), b"hello");
impl MetadataValue<Binary>
[src]
pub fn from_bytes(src: &[u8]) -> Self
[src]
Convert a byte slice to a MetadataValue<Binary>
.
Examples
let val = BinaryMetadataValue::from_bytes(b"hello\xfa"); assert_eq!(val, &b"hello\xfa"[..]);
Trait Implementations
impl<KeyVE: ValueEncoding> From<MetadataKey<KeyVE>> for MetadataValue<Ascii>
[src]
fn from(h: MetadataKey<KeyVE>) -> MetadataValue<Ascii>
[src]
impl From<u16> for MetadataValue<Ascii>
[src]
fn from(num: u16) -> MetadataValue<Ascii>
[src]
impl From<i16> for MetadataValue<Ascii>
[src]
fn from(num: i16) -> MetadataValue<Ascii>
[src]
impl From<u32> for MetadataValue<Ascii>
[src]
fn from(num: u32) -> MetadataValue<Ascii>
[src]
impl From<i32> for MetadataValue<Ascii>
[src]
fn from(num: i32) -> MetadataValue<Ascii>
[src]
impl From<u64> for MetadataValue<Ascii>
[src]
fn from(num: u64) -> MetadataValue<Ascii>
[src]
impl From<i64> for MetadataValue<Ascii>
[src]
fn from(num: i64) -> MetadataValue<Ascii>
[src]
impl From<usize> for MetadataValue<Ascii>
[src]
fn from(num: usize) -> MetadataValue<Ascii>
[src]
impl From<isize> for MetadataValue<Ascii>
[src]
fn from(num: isize) -> MetadataValue<Ascii>
[src]
impl<VE: ValueEncoding> From<MetadataValue<VE>> for Bytes
[src]
fn from(value: MetadataValue<VE>) -> Bytes
[src]
impl<'a, VE: ValueEncoding> From<&'a MetadataValue<VE>> for MetadataValue<VE>
[src]
fn from(t: &'a MetadataValue<VE>) -> Self
[src]
impl<VE: ValueEncoding> AsRef<[u8]> for MetadataValue<VE>
[src]
impl<VE: ValueEncoding> Ord for MetadataValue<VE>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for MetadataValue<VE>
[src]
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<VE: ValueEncoding> PartialOrd<str> for MetadataValue<VE>
[src]
fn partial_cmp(&self, other: &str) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<VE: ValueEncoding> PartialOrd<[u8]> for MetadataValue<VE>
[src]
fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for str
[src]
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for [u8]
[src]
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<VE: ValueEncoding> PartialOrd<String> for MetadataValue<VE>
[src]
fn partial_cmp(&self, other: &String) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for String
[src]
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'a, VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for &'a MetadataValue<VE>
[src]
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'a, VE: ValueEncoding, T: ?Sized> PartialOrd<&'a T> for MetadataValue<VE> where
MetadataValue<VE>: PartialOrd<T>,
[src]
MetadataValue<VE>: PartialOrd<T>,
fn partial_cmp(&self, other: &&'a T) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'a, VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for &'a str
[src]
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<VE: Clone + ValueEncoding> Clone for MetadataValue<VE>
[src]
fn clone(&self) -> MetadataValue<VE>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for MetadataValue<VE>
[src]
fn eq(&self, other: &MetadataValue<VE>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<VE: ValueEncoding> PartialEq<str> for MetadataValue<VE>
[src]
fn eq(&self, other: &str) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<VE: ValueEncoding> PartialEq<[u8]> for MetadataValue<VE>
[src]
fn eq(&self, other: &[u8]) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for str
[src]
fn eq(&self, other: &MetadataValue<VE>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for [u8]
[src]
fn eq(&self, other: &MetadataValue<VE>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<VE: ValueEncoding> PartialEq<String> for MetadataValue<VE>
[src]
fn eq(&self, other: &String) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for String
[src]
fn eq(&self, other: &MetadataValue<VE>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a, VE: ValueEncoding> PartialEq<MetadataValue<VE>> for &'a MetadataValue<VE>
[src]
fn eq(&self, other: &MetadataValue<VE>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a, VE: ValueEncoding, T: ?Sized> PartialEq<&'a T> for MetadataValue<VE> where
MetadataValue<VE>: PartialEq<T>,
[src]
MetadataValue<VE>: PartialEq<T>,
fn eq(&self, other: &&'a T) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a, VE: ValueEncoding> PartialEq<MetadataValue<VE>> for &'a str
[src]
fn eq(&self, other: &MetadataValue<VE>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<VE: ValueEncoding> Eq for MetadataValue<VE>
[src]
impl<VE: ValueEncoding> Debug for MetadataValue<VE>
[src]
impl<VE: Hash + ValueEncoding> Hash for MetadataValue<VE>
[src]
fn hash<__HVE: Hasher>(&self, state: &mut __HVE)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromStr for MetadataValue<Ascii>
[src]
type Err = InvalidMetadataValue
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<MetadataValue<Ascii>, Self::Err>
[src]
Auto Trait Implementations
impl<VE> Unpin for MetadataValue<VE> where
VE: Unpin,
VE: Unpin,
impl<VE> Sync for MetadataValue<VE> where
VE: Sync,
VE: Sync,
impl<VE> Send for MetadataValue<VE> where
VE: Send,
VE: Send,
impl<VE> UnwindSafe for MetadataValue<VE> where
VE: UnwindSafe,
VE: UnwindSafe,
impl<VE> RefUnwindSafe for MetadataValue<VE> where
VE: RefUnwindSafe,
VE: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,