Module serde_tagged::ser::adj::map

source ·
Expand description

Serialization of adjacently tagged values using maps.

Tagging a value adjacently using this strategy will create a map with two entries, one entry contains a mapping from the tag-key to the tag and the other entry contains a mapping from the value-key to the value.

§Warning

If the deserialization-process depends on the tag (i.e. with deserialize and/or Visitor), deserialization of map-based adjacently tagged values is only supported for self-describing formats.

§Examples serializing to JSON

Serializing a value

let foo: i32 = 42;

let mut serializer = serde_json::Serializer::new(std::io::stdout());
serde_tagged::ser::adj::map::serialize(&mut serializer, "t", "bar", "c", &foo).unwrap();

with a tag-key of "t", a tag value of "bar", and a value-key of "c" will produce

{
    "t": "bar",
    "c": 42
}

§A Simple struct

Serializing a value foo with

#[derive(Serialize)]
struct Foo {
    bar: &'static str,
}

let foo = Foo { bar: "baz" };

let mut serializer = serde_json::Serializer::new(std::io::stdout());
serde_tagged::ser::adj::map::serialize(&mut serializer, "t", "my-tag", "c", &foo).unwrap();

with a tag-key of "t", a tag value of "my-tag", and a value-key of "c" will produce

{
    "t": "my-tag",
    "c": { "bar": "baz" }
}

Structs§

  • A serializer that Serializes the specified tag-key, tag, value-key and value as map.

Functions§

  • Serializes the specified tag-key, tag, value-key and value as map.