serde-rs.github.io icon indicating copy to clipboard operation
serde-rs.github.io copied to clipboard

Improve confusing wording in `tag` container attribute's description

Open JohnDowson opened this issue 1 year ago • 1 comments

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.

JohnDowson avatar Sep 18 '24 02:09 JohnDowson

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.

dtolnay avatar Sep 18 '24 02:09 dtolnay