pub trait Headers {
// Required methods
fn count(&self) -> usize;
fn try_get(&self, idx: usize) -> Option<Header<'_, &[u8]>>;
// Provided methods
fn get(&self, idx: usize) -> Header<'_, &[u8]> { ... }
fn get_as<V>(&self, idx: usize) -> Result<Header<'_, &V>, V::Error>
where V: FromBytes + ?Sized { ... }
fn try_get_as<V>(
&self,
idx: usize,
) -> Option<Result<Header<'_, &V>, V::Error>>
where V: FromBytes + ?Sized { ... }
fn iter(&self) -> HeadersIter<'_, Self> ⓘ
where Self: Sized { ... }
}
Expand description
A generic representation of Kafka message headers.
This trait represents readable message headers. Headers are key-value pairs that can be sent alongside every message. Only read-only methods are provided by this trait, as the underlying storage might not allow modification.
Required Methods§
Provided Methods§
sourcefn get(&self, idx: usize) -> Header<'_, &[u8]>
fn get(&self, idx: usize) -> Header<'_, &[u8]>
Gets the specified header, where the first header corresponds to index 0.
Panics if the index is out of bounds.
sourcefn get_as<V>(&self, idx: usize) -> Result<Header<'_, &V>, V::Error>
fn get_as<V>(&self, idx: usize) -> Result<Header<'_, &V>, V::Error>
Like Headers::get
, but the value of the header will be converted
to the specified type.
Panics if the index is out of bounds.
sourcefn try_get_as<V>(&self, idx: usize) -> Option<Result<Header<'_, &V>, V::Error>>
fn try_get_as<V>(&self, idx: usize) -> Option<Result<Header<'_, &V>, V::Error>>
Like Headers::get
, but returns an option if the header is out of
bounds rather than panicking.
sourcefn iter(&self) -> HeadersIter<'_, Self> ⓘwhere
Self: Sized,
fn iter(&self) -> HeadersIter<'_, Self> ⓘwhere
Self: Sized,
Iterates over all headers in order.
Object Safety§
This trait is not object safe.