pub struct Payload(/* private fields */);Expand description
Ledger payload: a JSON object with every float refused, at construction and again on read (determinism rule 6). Keys serialize sorted (serde_json’s default BTreeMap), which is part of the canonical bytes.
Implementations§
Source§impl Payload
impl Payload
pub fn empty() -> Self
Sourcepub fn of(record: &impl Serialize) -> Result<Self, AxError>
pub fn of(record: &impl Serialize) -> Result<Self, AxError>
The way in: one of the record structs in crate::event::record,
encoded as the object a ledger line carries. Every writer goes
through here, so the keys of a kind are spelled in exactly one
place: the struct.
§Errors
Refuses a record that does not encode to a JSON object, and any
float inside one, for the reasons Payload::new gives.
Sourcepub fn read<T: DeserializeOwned>(&self) -> Result<T, AxError>
pub fn read<T: DeserializeOwned>(&self) -> Result<T, AxError>
The way out: the record struct this payload was written from.
A field a record written by an older build may omit carries
#[serde(default)] on the struct, so the tolerance is declared
once per key rather than at each reader. Unknown keys pass, so a
newer writer never breaks an older reader.
Deserializes from the held map by reference, so a read allocates
only what T owns, never a second copy of the payload.
§Errors
A payload this build cannot read as T.