Module ketos::value_encode
[−]
[src]
Implements encoding Rust values into Value
instances.
Encoding and decoding is performed using the Serialize
/Deserialize
traits of the serde
crate.
struct
values are encoded as a list of two elements: the struct
name
followed by a series of fields. Tuple structs contain an ordered list of
values, while traditional structs contain a list of inline :key value
pairs.
For example, given a struct
definition such as:
#[derive(Debug, Deserialize, Serialize)] struct MyStruct { a: i32, b: Vec<i32>, }
The value MyStruct{a: 1, b: vec![2, 3, 4]}
would be encoded as
(MyStruct (:a 1 :b (2 3 4)))
.
Similarly, enum
values are encoded as a list of three elements:
the enum
name, the variant name, and a list of any values contained
in the variant.
Functions
encode_value |
Encodes a Rust type into a |