Skip to main content

Headers

Trait Headers 

Source
pub trait Headers {
    // Required methods
    fn add_header(
        &mut self,
        header: RecordHeader,
    ) -> Result<(), LocalIllegalStateError>;
    fn add_key_value(
        &mut self,
        key: &str,
        value: Option<&[u8]>,
    ) -> Result<(), LocalIllegalStateError>;
    fn remove(&mut self, key: &str) -> Result<(), LocalIllegalStateError>;
    fn last_header(&self, key: &str) -> Option<&RecordHeader>;
    fn headers(&self, key: &str) -> Vec<&RecordHeader>;
    fn to_array(&self) -> &[RecordHeader];
    fn iter(&self) -> Iter<'_, RecordHeader>;
}
Expand description

A mutable ordered collection of Header objects.

Note that multiple headers may have the same key. The order of headers is preserved in the order they were added.

Corresponds to Java’s org.apache.kafka.common.header.Headers.

Required Methods§

Source

fn add_header( &mut self, header: RecordHeader, ) -> Result<(), LocalIllegalStateError>

Adds a header (key inside), to the end, returning if the operation succeeded.

Translates Java’s Headers add(Header header) (Headers.java:34). Java overloads add with add(String key, byte[] value); the two parameter lists have nothing in common, so under CLAUDE.md §2 neither overload keeps the plain name and both are suffixed with their parameter names.

§Errors

Returns an error if headers are in a read-only state.

Source

fn add_key_value( &mut self, key: &str, value: Option<&[u8]>, ) -> Result<(), LocalIllegalStateError>

Creates and adds a header, to the end, returning if the operation succeeded.

Translates Java’s Headers add(String key, byte[] value) (Headers.java:44) — see add_header for why neither overload keeps the plain name.

The key and value are borrowed; the allocation is performed internally.

§Errors

Returns an error if headers are in a read-only state.

Source

fn remove(&mut self, key: &str) -> Result<(), LocalIllegalStateError>

Removes all headers for the given key returning if the operation succeeded, while preserving the insertion order of the remaining headers.

§Errors

Returns an error if headers are in a read-only state.

Source

fn last_header(&self, key: &str) -> Option<&RecordHeader>

Returns just one (the very last) header for the given key, if present.

Source

fn headers(&self, key: &str) -> Vec<&RecordHeader>

Returns all headers for the given key, in the order they were added in.

Translates Java’s Iterable<Header> headers(String key) (Headers.java:71), which is not overloaded — so the plain translated name is the whole name (CLAUDE.md §2).

Source

fn to_array(&self) -> &[RecordHeader]

Returns all headers as a slice.

If no headers are present an empty slice is returned.

Source

fn iter(&self) -> Iter<'_, RecordHeader>

Returns an iterator over the headers.

Implementors§