Wado
<!-- Auto-generated by: wado doc -f markdown core:value --> <!-- Do not edit this file directly. -->

core:value

Dynamically-typed, format-agnostic value type.

Value represents any value the serde data model can carry, shared by every self-describing format (core:json, core:cbor). It implements Serialize and Deserialize, so it round-trips through from_bytes / to_bytes with no per-type work.

It is a general dynamic value, so it deliberately contains no format-specific concepts (no CBOR Tag, no Simple): a single opaque escape hatch, Unknown, carries the raw encoded bytes of anything the model cannot represent. Bytes (a semantic byte-string value) and Unknown (raw, format-specific encoded bytes) are distinct and must not be conflated.

Synopsis

assert to_value(&[1, 2, 3]) matches { Ok(List(items)) && items.len() == 3 };
assert to_value(&"wado") matches { Ok(String(s)) && s == "wado" };

let v: Value = from_bytes("{\"x\":1,\"y\":[true,null]}").unwrap();
assert v matches { Object(fields) && fields.len() == 2 };
assert to_bytes::<Value>(&v) matches { Ok(bytes) && bytes.len() > 0 };

Functions

pub fn to_value<T: Serialize>(value: &T) -> Result<Value, SerializeError>

Build a Value from any Serialize value — the serde to_value analog.

Direct: it drives a Value-building Serializer with no intermediate encoding, so it preserves the data model (Int vs UInt vs Float, object key order, variant shape) that a round-trip through a text format like JSON would flatten.

Structs

pub struct ValueSerializer

Fields are private.

impl Serializer for ValueSerializer

fn serialize_i32(&mut self, v: i32) -> Result<(), SerializeError>
fn serialize_i64(&mut self, v: i64) -> Result<(), SerializeError>
fn serialize_u32(&mut self, v: u32) -> Result<(), SerializeError>
fn serialize_u64(&mut self, v: u64) -> Result<(), SerializeError>
fn serialize_i128(&mut self, v: i128) -> Result<(), SerializeError>
fn serialize_u128(&mut self, v: u128) -> Result<(), SerializeError>
fn serialize_f32(&mut self, v: f32) -> Result<(), SerializeError>
fn serialize_f64(&mut self, v: f64) -> Result<(), SerializeError>
fn serialize_bool(&mut self, v: bool) -> Result<(), SerializeError>
fn serialize_char(&mut self, v: char) -> Result<(), SerializeError>
fn serialize_string(&mut self, v: &String) -> Result<(), SerializeError>
fn serialize_null(&mut self) -> Result<(), SerializeError>
fn serialize_bytes(&mut self, v: ByteSlice) -> Result<(), SerializeError>
fn begin_seq(&mut self, len: i32) -> Result<ValueSeqSerializer, SerializeError>
fn begin_map(&mut self, len: i32) -> Result<ValueMapSerializer, SerializeError>
fn begin_struct(&mut self, name: &String, fields: i32) -> Result<ValueStructSerializer, SerializeError>
fn serialize_unit_variant(&mut self, type_name: &String, variant_name: &String, disc: i32) -> Result<(), SerializeError>
fn begin_variant(&mut self, type_name: &String, variant_name: &String, disc: i32) -> Result<ValueVariantSerializer, SerializeError>

Variants

pub variant Value

A dynamically-typed, format-agnostic value.

JSON only ever produces Null / Bool / Float / String / List / Object (it has no integer/float distinction and no byte strings); the remaining arms are produced by binary formats such as CBOR.

Null

Bool(bool)

Int(i64)

UInt(u64)

Int128(i128)

UInt128(u128)

Float(f64)

String(String)

Bytes(ByteList)

List(List<Value>)

Object(TreeMap<String, Value>)

Undefined

Unknown(ByteList)