Skip to main content

HeaderValue

Struct HeaderValue 

Source
pub struct HeaderValue { /* private fields */ }
Expand description

A string that can be used to represent an header value

HeaderValue contains raw bytes that are guaranteed 1 to contain a valid header value that meets the following requirements:

  • The value does not contain \r or \n bytes

The value may be empty and may contain arbitrary non-UTF-8 bytes: the NATS server relays header values verbatim, and other clients (like nats.go) are able to produce such values.

HeaderValue can be constructed from HeaderValue::from_static, HeaderValue::from_bytes, or any of the TryFrom implementations.


  1. Because HeaderValue::from_dangerous_value is safe to call, unsafe code must not assume any of the above invariants. 

Implementations§

Source§

impl HeaderValue

Source

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

Construct HeaderValue from a static string

§Panics

Will panic if value isn’t a valid HeaderValue

Source

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

Construct a HeaderValue from raw bytes, validating the value

§Errors

Returns an error if value contains \r or \n.

Source

pub fn from_dangerous_value(value: Bytes) -> Self

Construct a HeaderValue from a Bytes, without checking invariants

This method bypasses invariants checks implemented by HeaderValue::from_static, HeaderValue::from_bytes, and all TryFrom implementations.

§Security

While calling this method can eliminate the runtime performance cost of checking the value, constructing HeaderValue with an invalid value and then calling the NATS server with it can cause serious security issues. When in doubt use HeaderValue::from_static, HeaderValue::from_bytes, or any of the TryFrom implementations.

Source

pub fn to_str(&self) -> Result<&str, HeaderValueToStrError>

Try to view this header value as a &str

§Errors

Returns HeaderValueToStrError if the value contains bytes that are not valid UTF-8.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the raw bytes of the header value

Trait Implementations§

Source§

impl AsRef<[u8]> for HeaderValue

Source§

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

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

impl Clone for HeaderValue

Source§

fn clone(&self) -> HeaderValue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for HeaderValue

Source§

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

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

impl Display for HeaderValue

Source§

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

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

impl Eq for HeaderValue

Source§

impl FromStr for HeaderValue

Source§

type Err = HeaderValueValidateError

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

fn from_str(value: &str) -> Result<Self, Self::Err>

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

impl Ord for HeaderValue

Source§

fn cmp(&self, other: &HeaderValue) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for HeaderValue

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for HeaderValue

Source§

fn partial_cmp(&self, other: &HeaderValue) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for HeaderValue

Source§

impl TryFrom<ByteString> for HeaderValue

Source§

type Error = HeaderValueValidateError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ByteString) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for HeaderValue

Source§

type Error = HeaderValueValidateError

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

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§

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

Source§

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

Source§

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.