Skip to main content

Flattrs

Struct Flattrs 

Source
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

Source

pub fn new() -> Self

Create a new empty Flattrs.

Source

pub fn from_part(part: Part) -> Self

Create from a Part.

Source

pub fn to_part(&self) -> Part

Convert to wire format for transmission.

Returns a [Part] for zero-copy serialization through the multipart codec.

Source

pub fn encoded_len(&self) -> usize

Return the encoded buffer length without copying it.

Source

pub fn validate_wire(&self) -> Result<(), FlattrsValidationError>

Validate the private wire structure without interpreting entry values.

This checks for a complete count header, the declared number of complete entries, and exact buffer consumption. Callers may layer additional policy such as key uniqueness or size bounds on top.

Source

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
Source

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].

Source

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).

Source

pub fn contains_key<T>(&self, key: Key<T>) -> bool

Check if a key exists.

Source

pub fn is_empty(&self) -> bool

Returns true if empty.

Source

pub fn len(&self) -> usize

Returns the number of entries.

Source

pub fn from_attrs(attrs: &Attrs) -> Self

Convert from an existing Attrs by serializing all values.

Source

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 Clone for Flattrs

Source§

fn clone(&self) -> Flattrs

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Flattrs

Source§

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

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

impl Default for Flattrs

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Flattrs

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Flattrs

Source§

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

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

impl Eq for Flattrs

Source§

impl From<&Attrs> for Flattrs

Source§

fn from(attrs: &Attrs) -> Self

Converts to this type from the input type.
Source§

impl From<Attrs> for Flattrs

Source§

fn from(attrs: Attrs) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Flattrs

Equality over the (key hash, serialized bytes) entries, independent of their order in the buffer.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Flattrs

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> QuoteExt for T
where T: ?Sized,

§

fn push_quoted<'q, Q, S>(&mut self, _q: Q, s: S)
where Q: QuoteInto<T>, S: Into<Quotable<'q>>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more