pub struct Headers { /* private fields */ }Expand description
Case-insensitive map of broker-message headers.
Keys are normalized to ASCII lowercase on insertion. Values are stored as Bytes to support
arbitrary binary metadata. Typed accessors are provided for well-known fields commonly carried
by message brokers; unknown headers are read through Headers::get.
§Examples
use ruststream::Headers;
let mut h = Headers::new();
h.insert("Content-Type", "application/json");
h.insert("X-Tenant-Id", "acme");
assert_eq!(h.content_type(), Some("application/json"));
assert_eq!(h.get("x-tenant-id"), Some(b"acme".as_slice()));Implementations§
Source§impl Headers
impl Headers
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Returns an empty header map with capacity for at least cap entries.
Sourcepub fn insert(
&mut self,
name: impl Into<String>,
value: impl Into<Bytes>,
) -> Option<Bytes>
pub fn insert( &mut self, name: impl Into<String>, value: impl Into<Bytes>, ) -> Option<Bytes>
Inserts a header value, returning the previous value under that key if any.
The key is normalized to ASCII lowercase.
Sourcepub fn get(&self, name: &str) -> Option<&[u8]>
pub fn get(&self, name: &str) -> Option<&[u8]>
Returns the raw bytes of a header value, or None if the header is absent.
Sourcepub fn get_str(&self, name: &str) -> Option<&str>
pub fn get_str(&self, name: &str) -> Option<&str>
Returns the value of a header decoded as UTF-8, or None if absent or not valid UTF-8.
Sourcepub fn remove(&mut self, name: &str) -> Option<Bytes>
pub fn remove(&mut self, name: &str) -> Option<Bytes>
Removes a header by name and returns its previous value, if any.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &[u8])>
pub fn iter(&self) -> impl Iterator<Item = (&str, &[u8])>
Iterates over (name, value) pairs. Names are returned in their normalized lowercase form.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Returns the value of the content-type header decoded as UTF-8.
Sourcepub fn correlation_id(&self) -> Option<&str>
pub fn correlation_id(&self) -> Option<&str>
Returns the value of the correlation-id header decoded as UTF-8.
Sourcepub fn reply_to(&self) -> Option<&str>
pub fn reply_to(&self) -> Option<&str>
Returns the value of the reply-to header decoded as UTF-8.
Sourcepub fn message_id(&self) -> Option<&str>
pub fn message_id(&self) -> Option<&str>
Returns the value of the message-id header decoded as UTF-8.