Skip to main content

Headers

Struct Headers 

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

Application-defined metadata Reliar does not understand: a validating newtype, never a HashMap alias and never exposed through Deref (ADR 0011). Reserves the entire reliar- prefix (case-insensitive) so framework metadata is never duplicated here — see Metadata for the one canonical source of truth (ADR 0004).

use reliar_core::Headers;

let mut headers = Headers::default();
headers.insert("x-import-batch", "2026-09-04")?;

assert_eq!(headers.get("x-import-batch"), Some("2026-09-04"));
// The entire `reliar-` prefix is reserved for framework metadata, case-insensitively.
assert!(headers.insert("Reliar-Correlation-Id", "nope").is_err());

Implementations§

Source§

impl Headers

Source

pub const RESERVED_PREFIX: &'static str = "reliar-"

Case-insensitively reserved prefix; Self::insert rejects any key starting with it.

Source

pub const MAX_KEY_LEN: usize = 128

Maximum key length in bytes.

Source

pub const MAX_VALUE_LEN: usize = 1024

Maximum value length in bytes.

Source

pub const MAX_COUNT: usize = 32

Maximum number of distinct headers on one envelope.

Source

pub fn insert( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> Result<Option<String>, HeaderError>

Inserts a header, returning the previous value if the key was already present.

Returns Err — never a silent drop or overwrite — for: the reserved reliar- prefix (matched case-insensitively, so Reliar-Correlation-Id is rejected too), an empty key, a key or value containing a control character (including CR/LF — a header-injection surface once a mapper writes the value onto the wire, same rule as crate::CorrelationId, crate::EndpointAddress and crate::ContentType), a key over Self::MAX_KEY_LEN, or a value over Self::MAX_VALUE_LEN. Replacing a key that is already present never counts against Self::MAX_COUNT; adding a genuinely new key while already at the cap does.

§Errors

Returns HeaderError for a reserved, empty, control-character-containing, or over-length key, a control-character-containing or over-length value, or a new key that would exceed Self::MAX_COUNT.

use reliar_core::Headers;

let mut headers = Headers::default();
assert_eq!(headers.insert("x-a", "1")?, None);
assert_eq!(headers.insert("x-a", "2")?, Some("1".to_string()));
Source

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

Looks up a header by exact key.

use reliar_core::Headers;

let mut headers = Headers::default();
headers.insert("x-a", "1")?;
assert_eq!(headers.get("x-a"), Some("1"));
assert_eq!(headers.get("x-missing"), None);
Source

pub fn remove(&mut self, key: &str) -> Option<String>

Removes a header, returning its value if present.

use reliar_core::Headers;

let mut headers = Headers::default();
headers.insert("x-a", "1")?;
assert_eq!(headers.remove("x-a"), Some("1".to_string()));
assert_eq!(headers.remove("x-a"), None);
Source

pub fn len(&self) -> usize

The number of headers stored.

use reliar_core::Headers;

let mut headers = Headers::default();
assert_eq!(headers.len(), 0);
headers.insert("x-a", "1")?;
assert_eq!(headers.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns true if no headers are stored.

use reliar_core::Headers;

let mut headers = Headers::default();
assert!(headers.is_empty());
headers.insert("x-a", "1")?;
assert!(!headers.is_empty());
Source

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

Iterates over every stored header as borrowed string slices.

use reliar_core::Headers;

let mut headers = Headers::default();
headers.insert("x-a", "1")?;
let collected: Vec<_> = headers.iter().collect();
assert_eq!(collected, vec![("x-a", "1")]);

Trait Implementations§

Source§

impl Clone for Headers

Source§

fn clone(&self) -> Headers

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 Headers

Never derived. Header values are application-supplied and may themselves be secrets: every value prints as <redacted>, keys print verbatim so the shape of a header set is still debuggable.

Source§

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

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

impl Default for Headers

Source§

fn default() -> Headers

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

impl Eq for Headers

Source§

impl PartialEq for Headers

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Headers

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.