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
impl Headers
Sourcepub const RESERVED_PREFIX: &'static str = "reliar-"
pub const RESERVED_PREFIX: &'static str = "reliar-"
Case-insensitively reserved prefix; Self::insert rejects any key starting with it.
Sourcepub const MAX_KEY_LEN: usize = 128
pub const MAX_KEY_LEN: usize = 128
Maximum key length in bytes.
Sourcepub const MAX_VALUE_LEN: usize = 1024
pub const MAX_VALUE_LEN: usize = 1024
Maximum value length in bytes.
Sourcepub fn insert(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> Result<Option<String>, HeaderError>
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()));Sourcepub fn get(&self, key: &str) -> Option<&str>
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);Sourcepub fn remove(&mut self, key: &str) -> Option<String>
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);Sourcepub fn len(&self) -> usize
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);Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
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 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.
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.