pub struct Flattrs { /* private fields */ }Expand description
Flat attribute storage for message headers.
Uses a single contiguous buffer with inline entry lengths.
Each entry is [key_hash: u64][len: u32][value: bytes].
Linear scan is used for lookup, which is optimal for small N.
Implementations§
Source§impl Flattrs
impl Flattrs
Sourcepub fn to_part(&self) -> Part
pub fn to_part(&self) -> Part
Convert to wire format for transmission.
Returns a Part for zero-copy serialization through the multipart codec.
Sourcepub fn set<T: Serialize>(&mut self, key: Key<T>, value: T)
pub fn set<T: Serialize>(&mut self, key: Key<T>, value: T)
Serialize a value and store it.
If the key already exists:
- Same size value: overwrite in place (no shifting)
- Different size: remove old entry and append new one
Sourcepub fn set_serialized(&mut self, key_hash: u64, serialized: &[u8])
pub fn set_serialized(&mut self, key_hash: u64, serialized: &[u8])
Set an entry by its (key_hash, serialized_value) pair,
replacing any existing entry under the same key_hash.
Collision semantics match [set]: in-place overwrite when
the new value is the same size, otherwise compact-and-append.
A later write under the same key hash is the value returned
by [get].
This is the lower-level companion to the typed [set] API,
intended for callers that already have a key hash and
pre-serialized bytes in hand — for example, copying
entries across Flattrs buffers without re-deserializing,
or stamping typed Attrs entries through a crate boundary
where the concrete Key<T> is out of scope. Most callers
should prefer [set].
Sourcepub fn get<T: AttrValue + DeserializeOwned>(&self, key: Key<T>) -> Option<T>
pub fn get<T: AttrValue + DeserializeOwned>(&self, key: Key<T>) -> Option<T>
Get a value, deserializing from the buffer.
Uses linear search which is optimal for the typical small number of headers (2-5 entries).
Sourcepub fn contains_key<T>(&self, key: Key<T>) -> bool
pub fn contains_key<T>(&self, key: Key<T>) -> bool
Check if a key exists.
Sourcepub fn from_attrs(attrs: &Attrs) -> Self
pub fn from_attrs(attrs: &Attrs) -> Self
Convert from an existing Attrs by serializing all values.
Sourcepub fn iter(&self) -> FlattrsIter<'_> ⓘ
pub fn iter(&self) -> FlattrsIter<'_> ⓘ
Iterate over all entries as (key_hash, value_bytes) pairs.
The byte slice is borrowed from the buffer — the caller must
not hold the returned slice across a mutation of this
Flattrs. Intended for generic copy paths that need to
transfer entries without knowing their typed schema (e.g.
filter-and-copy helpers keyed by meta marker). Callers that
need typed access should use the typed [get] API.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Flattrs
impl<'de> Deserialize<'de> for Flattrs
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Flattrs
impl RefUnwindSafe for Flattrs
impl Send for Flattrs
impl Sync for Flattrs
impl Unpin for Flattrs
impl UnsafeUnpin for Flattrs
impl UnwindSafe for Flattrs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more