Struct HeaderValue
pub struct HeaderValue {
inner: Bytes,
is_sensitive: bool,
}Expand description
Represents an HTTP header field value.
In practice, HTTP header field values are usually valid ASCII. However, the HTTP spec allows for a header value to contain opaque bytes as well. In this case, the header field value is not able to be represented as a string.
To handle this, the HeaderValue is usable as a type and can be compared
with strings and implements Debug. A to_str fn is provided that returns
an Err if the header value contains non visible ascii characters.
Fieldsยง
ยงinner: Bytesยงis_sensitive: boolImplementationsยง
ยงimpl HeaderValue
impl HeaderValue
pub const fn from_static(src: &'static str) -> HeaderValue
pub const fn from_static(src: &'static str) -> HeaderValue
Convert a static string to a HeaderValue.
This function will not perform any copying, however the string is checked to ensure that no invalid characters are present. Only visible ASCII characters (32-127) are permitted.
ยงPanics
This function panics if the argument contains invalid header value characters.
ยงExamples
let val = HeaderValue::from_static("hello");
assert_eq!(val, "hello");pub fn from_str(src: &str) -> Result<HeaderValue, InvalidHeaderValue>
pub fn from_str(src: &str) -> Result<HeaderValue, InvalidHeaderValue>
Attempt to convert a string to a HeaderValue.
If the argument contains invalid header value characters, an error is
returned. Only visible ASCII characters (32-127) are permitted. Use
from_bytes to create a HeaderValue 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 = HeaderValue::from_str("hello").unwrap();
assert_eq!(val, "hello");An invalid value
let val = HeaderValue::from_str("\n");
assert!(val.is_err());pub fn from_name(name: HeaderName) -> HeaderValue
pub fn from_name(name: HeaderName) -> HeaderValue
Converts a HeaderName into a HeaderValue
Since every valid HeaderName is a valid HeaderValue this is done infallibly.
ยงExamples
let val = HeaderValue::from_name(ACCEPT);
assert_eq!(val, HeaderValue::from_bytes(b"accept").unwrap());pub fn from_bytes(src: &[u8]) -> Result<HeaderValue, InvalidHeaderValue>
pub fn from_bytes(src: &[u8]) -> Result<HeaderValue, InvalidHeaderValue>
Attempt to convert a byte slice to a HeaderValue.
If the argument contains invalid header value bytes, an error is returned. Only byte values between 32 and 255 (inclusive) are permitted, excluding byte 127 (DEL).
This function is intended to be replaced in the future by a TryFrom
implementation once the trait is stabilized in std.
ยงExamples
let val = HeaderValue::from_bytes(b"hello\xfa").unwrap();
assert_eq!(val, &b"hello\xfa"[..]);An invalid value
let val = HeaderValue::from_bytes(b"\n");
assert!(val.is_err());Attempt to convert a Bytes buffer to a HeaderValue.
This will try to prevent a copy if the type passed is the type used internally, and will copy the data if it is not.
Convert a Bytes directly into a HeaderValue without validating.
This function does NOT validate that illegal bytes are not contained within the buffer.
ยงPanics
In a debug build this will panic if src is not valid UTF-8.
ยงSafety
src must contain valid UTF-8. In a release build it is undefined
behaviour to call this with src that is not valid UTF-8.
pub fn to_str(&self) -> Result<&str, ToStrError>
pub fn to_str(&self) -> Result<&str, ToStrError>
Yields a &str slice if the HeaderValue only contains visible ASCII
chars.
This function will perform a scan of the header value, checking all the characters.
ยงExamples
let val = HeaderValue::from_static("hello");
assert_eq!(val.to_str().unwrap(), "hello");pub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of self.
This length is in bytes.
ยงExamples
let val = HeaderValue::from_static("hello");
assert_eq!(val.len(), 5);pub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the HeaderValue has a length of zero bytes.
ยงExamples
let val = HeaderValue::from_static("");
assert!(val.is_empty());
let val = HeaderValue::from_static("hello");
assert!(!val.is_empty());pub fn as_bytes(&self) -> &[u8] โ
pub fn as_bytes(&self) -> &[u8] โ
Converts a HeaderValue to a byte slice.
ยงExamples
let val = HeaderValue::from_static("hello");
assert_eq!(val.as_bytes(), b"hello");pub fn set_sensitive(&mut self, val: bool)
pub fn set_sensitive(&mut self, val: bool)
Mark that the header value represents sensitive information.
ยงExamples
let mut val = HeaderValue::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
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. By marking header values as sensitive, components using this crate can be instructed to treat them with special care for security reasons. For example, caches can avoid storing sensitive values, and HPACK encoders used by HTTP/2.0 implementations can choose not to compress them.
Additionally, sensitive values will be masked by the Debug
implementation of HeaderValue.
Note that sensitivity is not factored into equality or ordering.
ยงExamples
let mut val = HeaderValue::from_static("my secret");
val.set_sensitive(true);
assert!(val.is_sensitive());
val.set_sensitive(false);
assert!(!val.is_sensitive());Trait Implementationsยง
ยงimpl AsRef<[u8]> for HeaderValue
impl AsRef<[u8]> for HeaderValue
ยงimpl Clone for HeaderValue
impl Clone for HeaderValue
ยงfn clone(&self) -> HeaderValue
fn clone(&self) -> HeaderValue
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreยงimpl Debug for HeaderValue
impl Debug for HeaderValue
ยงimpl<'a> From<&'a HeaderValue> for HeaderValue
impl<'a> From<&'a HeaderValue> for HeaderValue
ยงfn from(t: &'a HeaderValue) -> HeaderValue
fn from(t: &'a HeaderValue) -> HeaderValue
ยงimpl From<HeaderName> for HeaderValue
impl From<HeaderName> for HeaderValue
ยงfn from(h: HeaderName) -> HeaderValue
fn from(h: HeaderName) -> HeaderValue
ยงimpl From<HeaderValue> for AllowOrigin
impl From<HeaderValue> for AllowOrigin
ยงfn from(val: HeaderValue) -> AllowOrigin
fn from(val: HeaderValue) -> AllowOrigin
ยงimpl From<i16> for HeaderValue
impl From<i16> for HeaderValue
ยงfn from(num: i16) -> HeaderValue
fn from(num: i16) -> HeaderValue
ยงimpl From<i32> for HeaderValue
impl From<i32> for HeaderValue
ยงfn from(num: i32) -> HeaderValue
fn from(num: i32) -> HeaderValue
ยงimpl From<i64> for HeaderValue
impl From<i64> for HeaderValue
ยงfn from(num: i64) -> HeaderValue
fn from(num: i64) -> HeaderValue
ยงimpl From<isize> for HeaderValue
impl From<isize> for HeaderValue
ยงfn from(num: isize) -> HeaderValue
fn from(num: isize) -> HeaderValue
ยงimpl From<u16> for HeaderValue
impl From<u16> for HeaderValue
ยงfn from(num: u16) -> HeaderValue
fn from(num: u16) -> HeaderValue
ยงimpl From<u32> for HeaderValue
impl From<u32> for HeaderValue
ยงfn from(num: u32) -> HeaderValue
fn from(num: u32) -> HeaderValue
ยงimpl From<u64> for HeaderValue
impl From<u64> for HeaderValue
ยงfn from(num: u64) -> HeaderValue
fn from(num: u64) -> HeaderValue
ยงimpl From<usize> for HeaderValue
impl From<usize> for HeaderValue
ยงfn from(num: usize) -> HeaderValue
fn from(num: usize) -> HeaderValue
ยงimpl FromStr for HeaderValue
impl FromStr for HeaderValue
ยงtype Err = InvalidHeaderValue
type Err = InvalidHeaderValue
ยงfn from_str(s: &str) -> Result<HeaderValue, <HeaderValue as FromStr>::Err>
fn from_str(s: &str) -> Result<HeaderValue, <HeaderValue as FromStr>::Err>
s to return a value of this type. Read moreยงimpl Hash for HeaderValue
impl Hash for HeaderValue
ยงimpl Ord for HeaderValue
impl Ord for HeaderValue
ยงfn cmp(&self, other: &HeaderValue) -> Ordering
fn cmp(&self, other: &HeaderValue) -> Ordering
1.21.0 ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
ยงimpl<'a, T> PartialEq<&'a T> for HeaderValue
impl<'a, T> PartialEq<&'a T> for HeaderValue
ยงimpl PartialEq<[u8]> for HeaderValue
impl PartialEq<[u8]> for HeaderValue
ยงimpl<'a> PartialEq<HeaderValue> for &'a HeaderValue
impl<'a> PartialEq<HeaderValue> for &'a HeaderValue
ยงimpl<'a> PartialEq<HeaderValue> for &'a str
impl<'a> PartialEq<HeaderValue> for &'a str
ยงimpl PartialEq<HeaderValue> for [u8]
impl PartialEq<HeaderValue> for [u8]
ยงimpl PartialEq<HeaderValue> for String
impl PartialEq<HeaderValue> for String
ยงimpl PartialEq<HeaderValue> for str
impl PartialEq<HeaderValue> for str
ยงimpl PartialEq<String> for HeaderValue
impl PartialEq<String> for HeaderValue
ยงimpl PartialEq<str> for HeaderValue
impl PartialEq<str> for HeaderValue
ยงimpl PartialEq for HeaderValue
impl PartialEq for HeaderValue
ยงimpl<'a, T> PartialOrd<&'a T> for HeaderValue
impl<'a, T> PartialOrd<&'a T> for HeaderValue
ยงimpl PartialOrd<[u8]> for HeaderValue
impl PartialOrd<[u8]> for HeaderValue
ยงimpl<'a> PartialOrd<HeaderValue> for &'a HeaderValue
impl<'a> PartialOrd<HeaderValue> for &'a HeaderValue
ยงimpl<'a> PartialOrd<HeaderValue> for &'a str
impl<'a> PartialOrd<HeaderValue> for &'a str
ยงimpl PartialOrd<HeaderValue> for [u8]
impl PartialOrd<HeaderValue> for [u8]
ยงimpl PartialOrd<HeaderValue> for String
impl PartialOrd<HeaderValue> for String
ยงimpl PartialOrd<HeaderValue> for str
impl PartialOrd<HeaderValue> for str
ยงimpl PartialOrd<String> for HeaderValue
impl PartialOrd<String> for HeaderValue
ยงimpl PartialOrd<str> for HeaderValue
impl PartialOrd<str> for HeaderValue
ยงimpl PartialOrd for HeaderValue
impl PartialOrd for HeaderValue
ยงimpl<'a> TryFrom<&'a [u8]> for HeaderValue
impl<'a> TryFrom<&'a [u8]> for HeaderValue
ยงtype Error = InvalidHeaderValue
type Error = InvalidHeaderValue
ยงfn try_from(
t: &'a [u8],
) -> Result<HeaderValue, <HeaderValue as TryFrom<&'a [u8]>>::Error>
fn try_from( t: &'a [u8], ) -> Result<HeaderValue, <HeaderValue as TryFrom<&'a [u8]>>::Error>
ยงimpl<'a> TryFrom<&'a String> for HeaderValue
impl<'a> TryFrom<&'a String> for HeaderValue
ยงtype Error = InvalidHeaderValue
type Error = InvalidHeaderValue
ยงfn try_from(
s: &'a String,
) -> Result<HeaderValue, <HeaderValue as TryFrom<&'a String>>::Error>
fn try_from( s: &'a String, ) -> Result<HeaderValue, <HeaderValue as TryFrom<&'a String>>::Error>
ยงimpl<'a> TryFrom<&'a str> for HeaderValue
impl<'a> TryFrom<&'a str> for HeaderValue
ยงtype Error = InvalidHeaderValue
type Error = InvalidHeaderValue
ยงfn try_from(
t: &'a str,
) -> Result<HeaderValue, <HeaderValue as TryFrom<&'a str>>::Error>
fn try_from( t: &'a str, ) -> Result<HeaderValue, <HeaderValue as TryFrom<&'a str>>::Error>
ยงimpl TryFrom<String> for HeaderValue
impl TryFrom<String> for HeaderValue
ยงtype Error = InvalidHeaderValue
type Error = InvalidHeaderValue
ยงfn try_from(
t: String,
) -> Result<HeaderValue, <HeaderValue as TryFrom<String>>::Error>
fn try_from( t: String, ) -> Result<HeaderValue, <HeaderValue as TryFrom<String>>::Error>
ยงimpl TryFrom<Vec<u8>> for HeaderValue
impl TryFrom<Vec<u8>> for HeaderValue
ยงtype Error = InvalidHeaderValue
type Error = InvalidHeaderValue
impl Eq for HeaderValue
Auto Trait Implementationsยง
impl !Freeze for HeaderValue
impl RefUnwindSafe for HeaderValue
impl Send for HeaderValue
impl Sync for HeaderValue
impl Unpin for HeaderValue
impl UnwindSafe for HeaderValue
Blanket Implementationsยง
Sourceยงimpl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Sourceยงfn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Sourceยงfn adapt_into(self) -> D
fn adapt_into(self) -> D
Sourceยงimpl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Sourceยงfn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Sourceยงimpl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Sourceยงfn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Sourceยงtype Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
ยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Sourceยงimpl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Sourceยงfn components_from(colors: C) -> T
fn components_from(colors: C) -> T
ยงimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
ยงfn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.ยงfn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.ยงfn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Anyโs vtable from &Traitโs.ยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Anyโs vtable from &mut Traitโs.ยงimpl<T> DowncastSend for T
impl<T> DowncastSend for T
ยงimpl<T> DowncastSync for T
impl<T> DowncastSync for T
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Sourceยงimpl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Sourceยงfn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Sourceยงimpl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Sourceยงfn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Instrument for T
impl<T> Instrument for T
ยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงimpl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Sourceยงfn into_angle(self) -> U
fn into_angle(self) -> U
T.Sourceยงimpl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Sourceยงtype Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Sourceยงfn into_color(self) -> U
fn into_color(self) -> U
Sourceยงimpl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Sourceยงfn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
impl<T, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
ยงfn into_reactive_value(self) -> T
fn into_reactive_value(self) -> T
self into a T.Sourceยงimpl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Sourceยงfn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Pointable for T
impl<T> Pointable for T
ยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
ยงimpl<T> SerializableKey for T
impl<T> SerializableKey for T
ยงimpl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
ยงfn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
ยงfn into_taken(self) -> T
fn into_taken(self) -> T
Sourceยงimpl<T> ToHex for T
impl<T> ToHex for T
Sourceยงfn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Sourceยงfn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)Sourceยงimpl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Sourceยงtype Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Sourceยงfn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Sourceยงimpl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Sourceยงfn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more