pub struct Details { /* private fields */ }Expand description
Bounded key/value metadata attached to a KhiveError (max 8 pairs).
Stored as Cow<'static, str> pairs: zero-alloc for static string literals
(the common construction path) and owned strings on deserialization (no
memory leak). Both paths are no_std + alloc compatible.
When the source supplies more than 8 pairs, the wire shape stays bounded
at 8 entries, but the truncation is observable: the first 7 pairs are
retained and the 8th slot becomes DETAILS_TRUNCATED_KEY mapped to the
dropped-pair count. DETAILS_TRUNCATED_KEY is a reserved key: a
client-supplied pair using that name is never retained as an ordinary
entry (PR #549) — it is stripped and folded into the
drop count instead, so a client can neither fake truncation on a small
map nor shadow the real indicator on an oversized one. The drop count
itself is tracked in an internal, non-serialized field
(Details::dropped_count) rather than parsed back out of the entry
list, so a same-shaped client map can’t spoof it either.
Implementations§
Source§impl Details
impl Details
Sourcepub fn new<I>(pairs: I) -> Self
pub fn new<I>(pairs: I) -> Self
Build Details from an iterable of (&'static str, &'static str) pairs.
Up to 8 pairs are kept as-is. When more than 8 are supplied, the first
7 client pairs are kept and the 8th slot is replaced with
DETAILS_TRUNCATED_KEY carrying the dropped-pair count, so the
truncation is observable rather than silent. A client-supplied pair
named DETAILS_TRUNCATED_KEY is always treated as reserved: it is
dropped (never stored as an ordinary entry) and counted, even when
the remaining pairs fit within the 8-entry bound.
Sourcepub fn dropped_count(&self) -> Option<usize>
pub fn dropped_count(&self) -> Option<usize>
Number of pairs dropped due to the 8-entry bound and/or a reserved-key collision, if any were.
Returns None when nothing was dropped. Returns
Some(dropped_count) otherwise, read from the internal truncation
flag set at construction/deserialization time — never re-parsed from
the entry list, so a client-supplied details_truncated pair can’t
spoof this value.