pub enum Value {
Int(i128),
Bytes(Vec<u8>),
Text(String),
List(Vec<Value>),
Map(Vec<(Value, Value)>),
Null,
Float(f64),
}Expand description
A deterministic-CBOR value, restricted to exactly the shapes macula’s wire format supports. There is no generic “any CBOR” here on purpose.
Variants§
Int(i128)
Signed, but the encodable range is asymmetric: -(2^64)..=u64::MAX,
matching the reference codec’s own u64/i128 split.
Bytes(Vec<u8>)
Text(String)
Also what an Erlang atom (frame-type names, field names, enum values) becomes on the wire — see the module doc.
List(Vec<Value>)
Map(Vec<(Value, Value)>)
Insertion order on construction; canonical key sort happens at encode time, not here. Decode refuses a duplicate key.
Null
Float(f64)
Always round-trips through binary64 — see the module doc’s note on why this diverges from RFC 8949’s canonical-form guidance.
Implementations§
Source§impl Value
impl Value
Sourcepub fn text(s: impl Into<String>) -> Self
pub fn text(s: impl Into<String>) -> Self
Convenience: build a Text value from anything Into<String>.
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Look up a field by text key. None if this isn’t a Map or the
key isn’t present — mirrors macula’s own field vocabulary, which
is always text keys (see the module doc’s atom/text note).
Sourcepub fn without(&self, keys: &[&str]) -> Value
pub fn without(&self, keys: &[&str]) -> Value
A new Map with the given text keys removed. Non-maps pass
through unchanged. Used to compute a frame’s signable bytes (the
frame minus signature/publisher_sig) — see crate::frame.
Sourcepub fn with_field(self, key: &str, value: Value) -> Value
pub fn with_field(self, key: &str, value: Value) -> Value
Insert or replace a field in a Map by text key, consuming and
returning self for chaining. A no-op on a non-map value.