enum Value
pub enum Value :: [Equatable, Debug]
Conforms to Equatable, Debug, Codable.
A tree of the ten forms: what any encoder is given and any decoder answers, as a value.
Value.of(v) is the tree a value writes, tree.read<T>() the value a tree reads as. A struct
is its name and its fields in order, a variant its enum's name, its own, its index and its
payload where it has one; a map is its entries in the order written.
Variants
Null
Bool(bool)
Int(int)
Uint(uint)
Float(float)
String(string)
Bytes(uint8[])
Seq(List<Value>)
Map(List<(Value, Value)>)
Struct(string, List<(string, Value)>)
Variant(string, string, int, ?Box<Value>)
Methods
pub static fn encoder(): ValueEncoder
Returns a new encoder that builds a tree.
pub static fn of<T :: [Encode]>(v: T): Value throws EncodeError
Returns the tree v writes.
Errors
Throws what encoding v throws.
pub fn read<T :: [Decode]>(): T throws DecodeError
Decodes a T out of this tree.
Errors
Throws DecodeError where the tree does not hold a T.
pub fn decoder(): ValueDecoder
Returns a decoder over this tree, to pass on.
fn encode<E :: [Encoder]>(&e: E): void throws EncodeError
static fn decode<D :: [Decoder]>(&d: D): Value throws DecodeError
Reads whatever form the decoder has next. A decoder answers the form it is asked for, so the tree asks in turn — null, a bool, an int, a uint, a float, a string, bytes, a sequence, a map — and takes the first that is no mismatch. A struct or a variant cannot be asked for without its name: a format's own tree knows its forms; this one reads the scalars and the two anonymous containers.
Errors
Throws DecodeError of kind TypeMismatch where the data holds a struct or a variant,
or what reading a nested value throws.