serde-rs.github.io
serde-rs.github.io copied to clipboard
Improve confusing wording in `tag` container attribute's description
Serializing a structure like this
#[derive(Serialize, Deserialize)]
#[serde(tag = "kind"]
enum Foo {
Bar(Bar),
}
#[derive(Serialize, Deserialize)]
#[serde(tag = "kind")]
struct Bar {
baz: String
}
results in duplicated kind fields, which is consistent with the struct being tagged externally, rather than the described behaviour of
Serialize the struct's name (or value of serde(rename)) as a field with the given key, in front of all the real fields of the struct. which suggests that the tag would be prepended to the struct's fields.
The original text is better, in my opinion. "External" in the context of a tag attribute suggests "externally tagged", which means a specific thing and is not the representation that #[serde(tag = "kind")] struct Bar {…} uses.