Struct tonic::metadata::MetadataValue
source · [−]#[repr(transparent)]pub struct MetadataValue<VE: ValueEncoding> { /* private fields */ }
Expand description
Represents a custom metadata field value.
MetadataValue
is used as the MetadataMap
value.
Implementations
sourceimpl<VE: ValueEncoding> MetadataValue<VE>
impl<VE: ValueEncoding> MetadataValue<VE>
sourcepub fn from_static(src: &'static str) -> Self
pub fn from_static(src: &'static str) -> Self
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!!");
sourcepub fn try_from_bytes(src: &[u8]) -> Result<Self, InvalidMetadataValueBytes>
pub fn try_from_bytes(src: &[u8]) -> Result<Self, InvalidMetadataValueBytes>
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());
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.
Convert a Bytes
directly into a MetadataValue
without validating.
For MetadataValue
Safety
This function does NOT validate that illegal bytes are not contained within the buffer.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
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());
sourcepub fn to_bytes(&self) -> Result<Bytes, InvalidMetadataValueBytes>
pub fn to_bytes(&self) -> Result<Bytes, InvalidMetadataValueBytes>
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");
sourcepub fn set_sensitive(&mut self, val: bool)
pub fn set_sensitive(&mut self, val: bool)
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());
sourcepub fn is_sensitive(&self) -> bool
pub fn is_sensitive(&self) -> bool
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());
sourcepub fn as_encoded_bytes(&self) -> &[u8]
pub fn as_encoded_bytes(&self) -> &[u8]
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");
sourceimpl MetadataValue<Ascii>
impl MetadataValue<Ascii>
sourcepub fn from_str(src: &str) -> Result<Self, InvalidMetadataValue>
pub fn from_str(src: &str) -> Result<Self, InvalidMetadataValue>
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());
sourcepub fn from_key<KeyVE: ValueEncoding>(key: MetadataKey<KeyVE>) -> Self
pub fn from_key<KeyVE: ValueEncoding>(key: MetadataKey<KeyVE>) -> Self
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());
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
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);
sourcepub fn to_str(&self) -> Result<&str, ToStrError>
pub fn to_str(&self) -> Result<&str, ToStrError>
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");
sourceimpl MetadataValue<Binary>
impl MetadataValue<Binary>
sourcepub fn from_bytes(src: &[u8]) -> Self
pub fn from_bytes(src: &[u8]) -> Self
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
sourceimpl<VE: ValueEncoding> AsRef<[u8]> for MetadataValue<VE>
impl<VE: ValueEncoding> AsRef<[u8]> for MetadataValue<VE>
sourceimpl<VE: Clone + ValueEncoding> Clone for MetadataValue<VE>
impl<VE: Clone + ValueEncoding> Clone for MetadataValue<VE>
sourcefn clone(&self) -> MetadataValue<VE>
fn clone(&self) -> MetadataValue<VE>
1.0.0const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<VE: ValueEncoding> Debug for MetadataValue<VE>
impl<VE: ValueEncoding> Debug for MetadataValue<VE>
sourceimpl<'a, VE: ValueEncoding> From<&'a MetadataValue<VE>> for MetadataValue<VE>
impl<'a, VE: ValueEncoding> From<&'a MetadataValue<VE>> for MetadataValue<VE>
sourcefn from(t: &'a MetadataValue<VE>) -> Self
fn from(t: &'a MetadataValue<VE>) -> Self
sourceimpl<VE: ValueEncoding> From<MetadataValue<VE>> for Bytes
impl<VE: ValueEncoding> From<MetadataValue<VE>> for Bytes
sourcefn from(value: MetadataValue<VE>) -> Bytes
fn from(value: MetadataValue<VE>) -> Bytes
sourceimpl<VE: ValueEncoding> Ord for MetadataValue<VE>
impl<VE: ValueEncoding> Ord for MetadataValue<VE>
sourceimpl<'a, VE: ValueEncoding, T: ?Sized> PartialEq<&'a T> for MetadataValue<VE>where
MetadataValue<VE>: PartialEq<T>,
impl<'a, VE: ValueEncoding, T: ?Sized> PartialEq<&'a T> for MetadataValue<VE>where
MetadataValue<VE>: PartialEq<T>,
sourceimpl<VE: ValueEncoding> PartialEq<[u8]> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialEq<[u8]> for MetadataValue<VE>
sourceimpl<'a, VE: ValueEncoding> PartialEq<MetadataValue<VE>> for &'a MetadataValue<VE>
impl<'a, VE: ValueEncoding> PartialEq<MetadataValue<VE>> for &'a MetadataValue<VE>
sourcefn eq(&self, other: &MetadataValue<VE>) -> bool
fn eq(&self, other: &MetadataValue<VE>) -> bool
sourceimpl<'a, VE: ValueEncoding> PartialEq<MetadataValue<VE>> for &'a str
impl<'a, VE: ValueEncoding> PartialEq<MetadataValue<VE>> for &'a str
sourcefn eq(&self, other: &MetadataValue<VE>) -> bool
fn eq(&self, other: &MetadataValue<VE>) -> bool
sourceimpl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for [u8]
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for [u8]
sourcefn eq(&self, other: &MetadataValue<VE>) -> bool
fn eq(&self, other: &MetadataValue<VE>) -> bool
sourceimpl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for MetadataValue<VE>
sourcefn eq(&self, other: &MetadataValue<VE>) -> bool
fn eq(&self, other: &MetadataValue<VE>) -> bool
sourceimpl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for String
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for String
sourcefn eq(&self, other: &MetadataValue<VE>) -> bool
fn eq(&self, other: &MetadataValue<VE>) -> bool
sourceimpl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for str
impl<VE: ValueEncoding> PartialEq<MetadataValue<VE>> for str
sourcefn eq(&self, other: &MetadataValue<VE>) -> bool
fn eq(&self, other: &MetadataValue<VE>) -> bool
sourceimpl<VE: ValueEncoding> PartialEq<String> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialEq<String> for MetadataValue<VE>
sourceimpl<VE: ValueEncoding> PartialEq<str> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialEq<str> for MetadataValue<VE>
sourceimpl<'a, VE: ValueEncoding, T: ?Sized> PartialOrd<&'a T> for MetadataValue<VE>where
MetadataValue<VE>: PartialOrd<T>,
impl<'a, VE: ValueEncoding, T: ?Sized> PartialOrd<&'a T> for MetadataValue<VE>where
MetadataValue<VE>: PartialOrd<T>,
sourceimpl<VE: ValueEncoding> PartialOrd<[u8]> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialOrd<[u8]> for MetadataValue<VE>
sourceimpl<'a, VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for &'a MetadataValue<VE>
impl<'a, VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for &'a MetadataValue<VE>
sourcefn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
1.0.0const fn lt(&self, other: &Rhs) -> bool
const fn lt(&self, other: &Rhs) -> bool
1.0.0const fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more1.0.0const fn gt(&self, other: &Rhs) -> bool
const fn gt(&self, other: &Rhs) -> bool
sourceimpl<'a, VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for &'a str
impl<'a, VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for &'a str
sourcefn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
1.0.0const fn lt(&self, other: &Rhs) -> bool
const fn lt(&self, other: &Rhs) -> bool
1.0.0const fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more1.0.0const fn gt(&self, other: &Rhs) -> bool
const fn gt(&self, other: &Rhs) -> bool
sourceimpl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for [u8]
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for [u8]
sourcefn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
1.0.0const fn lt(&self, other: &Rhs) -> bool
const fn lt(&self, other: &Rhs) -> bool
1.0.0const fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more1.0.0const fn gt(&self, other: &Rhs) -> bool
const fn gt(&self, other: &Rhs) -> bool
sourceimpl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for MetadataValue<VE>
sourcefn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
1.0.0const fn lt(&self, other: &Rhs) -> bool
const fn lt(&self, other: &Rhs) -> bool
1.0.0const fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more1.0.0const fn gt(&self, other: &Rhs) -> bool
const fn gt(&self, other: &Rhs) -> bool
sourceimpl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for String
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for String
sourcefn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
1.0.0const fn lt(&self, other: &Rhs) -> bool
const fn lt(&self, other: &Rhs) -> bool
1.0.0const fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more1.0.0const fn gt(&self, other: &Rhs) -> bool
const fn gt(&self, other: &Rhs) -> bool
sourceimpl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for str
impl<VE: ValueEncoding> PartialOrd<MetadataValue<VE>> for str
sourcefn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<Ordering>
1.0.0const fn lt(&self, other: &Rhs) -> bool
const fn lt(&self, other: &Rhs) -> bool
1.0.0const fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more1.0.0const fn gt(&self, other: &Rhs) -> bool
const fn gt(&self, other: &Rhs) -> bool
sourceimpl<VE: ValueEncoding> PartialOrd<String> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialOrd<String> for MetadataValue<VE>
sourceimpl<VE: ValueEncoding> PartialOrd<str> for MetadataValue<VE>
impl<VE: ValueEncoding> PartialOrd<str> for MetadataValue<VE>
impl<VE: ValueEncoding> Eq for MetadataValue<VE>
Auto Trait Implementations
impl<VE> RefUnwindSafe for MetadataValue<VE>where
VE: RefUnwindSafe,
impl<VE> Send for MetadataValue<VE>where
VE: Send,
impl<VE> Sync for MetadataValue<VE>where
VE: Sync,
impl<VE> Unpin for MetadataValue<VE>where
VE: Unpin,
impl<VE> UnwindSafe for MetadataValue<VE>where
VE: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere
T: Clone,
type Owned = T
type Owned = T
fn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;