pub struct AdditionalParams(/* private fields */);Expand description
Provider extras on a content block: a non-empty JSON object, by construction.
The serialized form is the bare object (#[serde(transparent)]), so the
wire shape of an additional_params field is a named key carrying an
object — never flattened into the block’s own key namespace. The type
carries the whole params contract, so no call-site convention is needed:
Some(AdditionalParams)always carries data. The constructors collapse an empty map toNoneand the inner map is private, so emptiness checks on a params field are a plainis_none()/is_some()— no tolerant shim, in-tree or out.- A non-object params value is unrepresentable in memory, so serialization can never emit a value deserialization rejects: what a live run writes, a restored run loads.
- On decode,
nulland{}canonicalize to an absent field (seeoptional_additional_params) and any other non-object value is a loud error.
The block structs themselves follow the complementary tolerance doctrine: a known field with the wrong shape is a loud decode error, an unknown key on a block is ignored (never captured, never replayed), and an unknown content-block tag is a loud error. The params are provider-specific: a serializer replays only params it recognizes as its own wire’s.
Implementations§
Source§impl AdditionalParams
impl AdditionalParams
Sourcepub fn new(map: Map<String, Value>) -> Option<AdditionalParams>
pub fn new(map: Map<String, Value>) -> Option<AdditionalParams>
The canonical constructor: None when the map is empty.
Sourcepub fn from_entries<K, I>(entries: I) -> Option<AdditionalParams>
pub fn from_entries<K, I>(entries: I) -> Option<AdditionalParams>
Build from (key, value) entries; None when the iterator yields
none. Option<(K, Value)> is such an iterator, so a conditional
single-key params reads as
AdditionalParams::from_entries(guard.then(|| (key, value))).
Sourcepub fn into_value(self) -> Value
pub fn into_value(self) -> Value
The params as a bare JSON object value.
Sourcepub fn merge(&mut self, incoming: AdditionalParams)
pub fn merge(&mut self, incoming: AdditionalParams)
Deep-merge incoming into self: arrays concatenate (streamed
citation deltas), objects merge recursively, scalars take the
incoming value.
Sourcepub fn wire_extras(&self, wire_key: &str) -> Option<&Map<String, Value>>
pub fn wire_extras(&self, wire_key: &str) -> Option<&Map<String, Value>>
The extras stored under a wire’s own key, when present — the
replay-side gate: a serializer asks for its key and never sees
another wire’s extras (capture is unconditional at ingest; replay is
gated here). A non-object value under the key yields None (it is
not that wire’s extras); a caller that must distinguish malformed
from absent — a warn path — pairs this with Self::get. Never a
hard error: extras were written by a previous turn, and failing
serialization over them would turn a persistence blemish into a
broken conversation.
Sourcepub fn into_wire_extras(self, wire_key: &str) -> Option<Map<String, Value>>
pub fn into_wire_extras(self, wire_key: &str) -> Option<Map<String, Value>>
Owned counterpart of Self::wire_extras for serialization paths
that already own the params (the common replay case): extracts the
wire’s object without cloning. Same gate semantics.
Sourcepub fn try_from_value(value: Value) -> Result<Option<AdditionalParams>, Value>
pub fn try_from_value(value: Value) -> Result<Option<AdditionalParams>, Value>
Build from a JSON value: Ok(None) for null and the empty object
(canonical absence), Ok(Some) for a non-empty object, and Err
handing the value back otherwise — a non-object is never silently
swallowed; the caller decides loud versus lossy.
Trait Implementations§
Source§impl Clone for AdditionalParams
impl Clone for AdditionalParams
Source§fn clone(&self) -> AdditionalParams
fn clone(&self) -> AdditionalParams
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more