pub struct Header { /* private fields */ }Expand description
One header field.
Implementations§
Source§impl Header
impl Header
Sourcepub fn build(
name: HeaderName,
value: impl Into<Bytes>,
) -> Result<Self, BuildError>
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
impl Header
Sourcepub fn name(&self) -> &HeaderName
pub fn name(&self) -> &HeaderName
The resolved header name.
Sourcepub fn value(&self) -> Cow<'_, [u8]>
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.
Sourcepub fn address_value_count(&self) -> Result<usize, AddressEditError>
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.
Sourcepub fn replace_address_uri(
&mut self,
value_index: usize,
uri: &Uri,
) -> Result<(), AddressEditError>
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.
Sourcepub fn replace_address_presentation(
&mut self,
value_index: usize,
display_name: Option<&str>,
uri: &Uri,
) -> Result<(), AddressEditError>
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.
Sourcepub fn warning_value_count(&self) -> Result<usize, WarningEditError>
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.
Sourcepub fn replace_warning_agent_with_pseudonym(
&mut self,
value_index: usize,
pseudonym: &[u8],
) -> Result<(), WarningEditError>
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.
Sourcepub fn without_address_value(
&self,
value_index: usize,
) -> Result<Option<Self>, AddressEditError>
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.