Skip to main content

Fields

Struct Fields 

Source
pub struct Fields(/* private fields */);
Expand description

The field lines of a request or a response, in the order they arrived.

A list rather than a map, because a field section is a list: RFC 9110 §5.3 lets a name repeat, and the order of the values under one name is part of what they mean. Lookups walk it, which for the two or three fields a CONNECT request carries is what any map would have done more slowly.

Names are compared without regard to case. On the wire they are lowercase already – RFC 9114 §4.2 makes an uppercase one malformed, and super::stream enforces it – so the folding is not what makes a lookup find the field; it is what keeps a lookup from depending on that rule holding somewhere else.

Implementations§

Source§

impl Fields

Source

pub fn new() -> Self

An empty field section.

Source

pub fn append(&mut self, name: impl Into<Box<str>>, value: FieldValue)

Adds a field, keeping every value a repeated name already had.

The name must be a lowercase token, since it goes on the wire as it is given and RFC 9114 §4.2 makes an uppercase one malformed. Asserted in debug builds, and for the reason FieldValue::from_static gives: every name this server appends is a literal in this tree or one field_name has already accepted, so a violation is a bug rather than something a peer can provoke – and a release build has no business panicking over it.

Source

pub fn get(&self, name: &str) -> Option<&FieldValue>

The first value of name, or None if there is none.

Source

pub fn get_all<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = &'a FieldValue>

Every value of name, in the order they arrived.

Source

pub fn contains(&self, name: &str) -> bool

Whether any field is named name.

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &FieldValue)>

Every field line, in the order they arrived.

Source

pub fn len(&self) -> usize

How many field lines there are, counting a repeated name once per value.

Source

pub fn is_empty(&self) -> bool

Whether there are no field lines at all.

Trait Implementations§

Source§

impl Clone for Fields

Source§

fn clone(&self) -> Fields

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 Fields

Source§

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

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

impl Default for Fields

Source§

fn default() -> Fields

Returns the “default value” for a type. Read more
Source§

impl<N: Into<Box<str>>> FromIterator<(N, FieldValue)> for Fields

Source§

fn from_iter<I: IntoIterator<Item = (N, FieldValue)>>(fields: I) -> Self

Creates a value from an iterator. Read more

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more