Skip to main content

Header

Struct Header 

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

One header field.

Implementations§

Source§

impl Header

Source

pub fn build( name: HeaderName, value: impl Into<Bytes>, ) -> Result<Self, BuildError>

Build a header, rejecting a value that could inject a line break.

This is the only public way to make a header, and it is fallible on purpose.

Source§

impl Header

Source

pub fn name(&self) -> &HeaderName

The resolved header name.

Source

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

The value exactly as it appeared, folding included.

Source

pub fn value(&self) -> Cow<'_, [u8]>

The value with line folding replaced by single spaces, and surrounding whitespace trimmed — the form header grammars are defined against (RFC 3261 §7.3.1).

Borrows when the value contains no folding, which is the common case.

Source

pub fn address_value_count(&self) -> Result<usize, AddressEditError>

How many address values this row carries.

The count uses the field’s shared address grammar. It is useful for projecting a stable wire-order index across repeated rows without decoding or searching for value bytes.

Source

pub fn replace_address_uri( &mut self, value_index: usize, uri: &Uri, ) -> Result<(), AddressEditError>

Replace the URI in one address value, indexed within this header row.

Only the parser-owned URI span changes. The display name may contain identical URI bytes; it is never considered because this operation consumes grammar ranges rather than searching the field. Failures leave the header unchanged.

Source

pub fn replace_address_presentation( &mut self, value_index: usize, display_name: Option<&str>, uri: &Uri, ) -> Result<(), AddressEditError>

Replace one address’s display name, brackets and URI as one parser-owned span.

The replacement always uses unambiguous name-address form. A present display name is quoted and escaped here; every byte outside the retained presentation span stays exact. Failures leave the header unchanged.

Source

pub fn warning_value_count(&self) -> Result<usize, WarningEditError>

How many complete Warning values this row carries.

The count uses the field’s shared Warning grammar and therefore rejects an incomplete code, missing agent or malformed quoted text instead of counting delimiters locally.

Source

pub fn replace_warning_agent_with_pseudonym( &mut self, value_index: usize, pseudonym: &[u8], ) -> Result<(), WarningEditError>

Replace one Warning agent with an RFC 3261 token pseudonym.

Only the parser-retained agent range changes. The code, separator spaces, quoted text, folding and list layout stay byte-identical. Failures leave the header unchanged.

Source

pub fn without_address_value( &self, value_index: usize, ) -> Result<Option<Self>, AddressEditError>

Return this row with one address value removed.

Ok(None) means the selected address was the row’s sole value, so the containing header collection must remove the field line. Returning a new row keeps this operation atomic and gives standalone Header users an honest representation of row absence.

Source

pub fn write_to(&self, out: &mut Vec<u8>)

Write this header as a field line, without the terminating CRLF.

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

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 Header

Source§

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

Formats the value using the given formatter. 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.

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> Same for T

Source§

type Output = T

Should always be Self
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.