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
impl MessageMetadata
Sourcepub fn with_timestamp_now() -> Self
pub fn with_timestamp_now() -> Self
Create metadata with the current timestamp.
Sourcepub fn source(self, source: impl Into<Arc<str>>) -> Self
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>.
Sourcepub fn key(self, key: impl Into<Arc<str>>) -> Self
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>.
Sourcepub fn header(
self,
name: impl Into<Arc<str>>,
value: impl Into<Arc<str>>,
) -> Self
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>.
Sourcepub fn get_header(&self, name: &str) -> Option<&str>
pub fn get_header(&self, name: &str) -> Option<&str>
Get a header by name.
Returns a &str reference to the header value if found.
Sourcepub fn get_source(&self) -> Option<&str>
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.
Sourcepub fn get_key(&self) -> Option<&str>
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.
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.
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.
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.
Sourcepub fn with_source_borrowed(self, source: &str) -> Self
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>.
Sourcepub fn with_source_interned<I: StringInternerTrait>(
self,
source: &str,
interner: &I,
) -> Self
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 interninterner- The string interner to use (must implementStringInternerTrait)
§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.
Sourcepub fn with_key_interned<I: StringInternerTrait>(
self,
key: &str,
interner: &I,
) -> Self
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 interninterner- The string interner to use (must implementStringInternerTrait)
§Returns
Self for method chaining
Sourcepub fn add_header_interned<I: StringInternerTrait>(
self,
name: &str,
value: &str,
interner: &I,
) -> Self
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 internvalue- The header value to interninterner- The string interner to use (must implementStringInternerTrait)
§Returns
Self for method chaining
Trait Implementations§
Source§impl Clone for MessageMetadata
impl Clone for MessageMetadata
Source§fn clone(&self) -> MessageMetadata
fn clone(&self) -> MessageMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more