MessageMetadata

Struct MessageMetadata 

Source
pub struct MessageMetadata {
    pub timestamp: Option<Duration>,
    pub source: Option<Arc<str>>,
    pub partition: Option<u32>,
    pub offset: Option<u64>,
    pub key: Option<Arc<str>>,
    pub headers: Vec<(Arc<str>, Arc<str>)>,
}
Expand description

Metadata associated with a message.

Uses Arc<str> for string fields to enable zero-copy string sharing in fan-out scenarios and reduce memory usage for repeated strings.

Fields§

§timestamp: Option<Duration>

When the message was created (as Duration since UNIX_EPOCH).

§source: Option<Arc<str>>

The source of the message (e.g., topic, file, etc.). Uses Arc<str> for zero-copy string sharing.

§partition: Option<u32>

Partition or shard information.

§offset: Option<u64>

Offset within the partition/source.

§key: Option<Arc<str>>

User-defined key for routing/grouping. Uses Arc<str> for zero-copy string sharing.

§headers: Vec<(Arc<str>, Arc<str>)>

Additional headers/attributes. Uses Arc<str> for both keys and values to enable zero-copy sharing.

Implementations§

Source§

impl MessageMetadata

Source

pub fn new() -> Self

Create new empty metadata.

Source

pub fn with_timestamp_now() -> Self

Create metadata with the current timestamp.

Source

pub fn timestamp(self, ts: Duration) -> Self

Set the timestamp.

Source

pub fn source(self, source: impl Into<Arc<str>>) -> Self

Set the source.

Accepts any type that can be converted to Arc<str>, including String, &str, and Arc<str>.

Source

pub fn partition(self, partition: u32) -> Self

Set the partition.

Source

pub fn offset(self, offset: u64) -> Self

Set the offset.

Source

pub fn key(self, key: impl Into<Arc<str>>) -> Self

Set the key.

Accepts any type that can be converted to Arc<str>, including String, &str, and Arc<str>.

Source

pub fn header( self, name: impl Into<Arc<str>>, value: impl Into<Arc<str>>, ) -> Self

Add a header.

Accepts any types that can be converted to Arc<str>, including String, &str, and Arc<str>.

Source

pub fn get_header(&self, name: &str) -> Option<&str>

Get a header by name.

Returns a &str reference to the header value if found.

Source

pub fn get_source(&self) -> Option<&str>

Get the source as a string reference.

Returns None if no source is set, or Some(&str) with the source value.

Source

pub fn get_key(&self) -> Option<&str>

Get the key as a string reference.

Returns None if no key is set, or Some(&str) with the key value.

Source

pub fn with_shared_source(self, source: Arc<str>) -> Self

Create metadata with shared source (for zero-copy scenarios).

This method accepts an Arc<str> for the source, enabling zero-copy sharing of source strings across multiple messages.

This is now equivalent to source() since MessageMetadata uses Arc<str> directly.

Source

pub fn with_shared_key(self, key: Arc<str>) -> Self

Create metadata with shared key (for zero-copy scenarios).

This method accepts an Arc<str> for the key, enabling zero-copy sharing of key strings across multiple messages.

This is now equivalent to key() since MessageMetadata uses Arc<str> directly.

Source

pub fn with_shared_header(self, name: Arc<str>, value: Arc<str>) -> Self

Add a header with shared strings (for zero-copy scenarios).

This method accepts Arc<str> for header name and value, enabling zero-copy sharing of header strings across multiple messages.

This is now equivalent to header() since MessageMetadata uses Arc<str> directly.

Source

pub fn with_source_borrowed(self, source: &str) -> Self

Create metadata with source from a borrowed string.

This is a convenience method that accepts &str and converts it to Arc<str>.

Source

pub fn with_source_interned<I: StringInternerTrait>( self, source: &str, interner: &I, ) -> Self

Create metadata with interned source string.

This method accepts a &str and a string interner, interns the string, and stores the interned Arc<str> as the source. This enables automatic string deduplication for repeated source values.

§Arguments
  • source - The source string to intern
  • interner - The string interner to use (must implement StringInternerTrait)
§Returns

Self for method chaining

§Note

This method accepts any type that implements StringInternerTrait, which is provided by streamweave-graph::StringInterner. For use with the graph package, pass a &StringInterner from streamweave-graph.

Source

pub fn with_key_interned<I: StringInternerTrait>( self, key: &str, interner: &I, ) -> Self

Create metadata with interned key string.

This method accepts a &str and a string interner, interns the string, and stores the interned Arc<str> as the key. This enables automatic string deduplication for repeated key values.

§Arguments
  • key - The key string to intern
  • interner - The string interner to use (must implement StringInternerTrait)
§Returns

Self for method chaining

Source

pub fn add_header_interned<I: StringInternerTrait>( self, name: &str, value: &str, interner: &I, ) -> Self

Add a header with interned strings.

This method accepts header name and value as &str, interns both strings, and adds the interned Arc<str> pair to headers. This enables automatic string deduplication for repeated header keys and values.

§Arguments
  • name - The header name to intern
  • value - The header value to intern
  • interner - The string interner to use (must implement StringInternerTrait)
§Returns

Self for method chaining

Trait Implementations§

Source§

impl Clone for MessageMetadata

Source§

fn clone(&self) -> MessageMetadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageMetadata

Source§

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

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

impl Default for MessageMetadata

Source§

fn default() -> MessageMetadata

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

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.