Module serde_tagged::ser::adj::tuple

source ·
Expand description

Serialization of adjacently tagged values using tuples.

Tagging a value adjacently using this strategy will create a tuple with two elements, where the first element will be the tag and the second element the value.

§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::tuple::serialize(&mut serializer, "bar", &foo).unwrap();

with a tag value of "bar" will produce

[ "bar", 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::tuple::serialize(&mut serializer, "my-tag", &foo).unwrap();

with a tag-value of "my-tag" will produce the following JSON output:

[ "my-tag", { "bar": "baz" } ]

Structs§

  • A serializer that serializes the specified tag and value as tuple.

Functions§

  • Serializes the specified tag and value as tuple.