From d7cd4e48bfa3e96cb2600b1d3871e2909a69b63a Mon Sep 17 00:00:00 2001 From: Tomasz Durda Date: Mon, 26 May 2025 10:18:58 +0200 Subject: [PATCH 1/2] Added info about sequence enum representations --- _src/enum-representations.md | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/_src/enum-representations.md b/_src/enum-representations.md index c5a8355..848805c 100644 --- a/_src/enum-representations.md +++ b/_src/enum-representations.md @@ -157,3 +157,47 @@ enum Data { The `serde` crate's "alloc" Cargo feature must be enabled to deserialize an untagged tagged enum. (It is enabled by default.) + +## Sequence format of the adjacently and internally tagged representations + +Both the adjacently tagged and internally tagged representations can be +expressed either via map or sequence syntax. For example: + +```rust +#[derive(Debug, Serialize, Deserialize)] +#[serde(tag = "type", content = "x")] +enum MyType { + Topic(i64), Sidebar(i64) +} + +fn main() {} +``` + +is equivalent to both + +```json +[ "Topic", 1 ] +``` + +and + +```json +{ "type": "Topic", "x": 1 } +``` + +### Disable the sequence format + +*(since serde v1.1.0)* + +In case you want to disable the sequence format, you can use the +`#[serde(seq=false)]`. + +```rust +#[derive(Debug, Serialize, Deserialize)] +#[serde(tag = "type", content = "x", seq=false)] +enum MyType { + Topic(i64), Sidebar(i64) +} +``` + +will casue the sequence syntax to be disabled. From 4599c43587e52242ee3fdcb1f1546787afc6d303 Mon Sep 17 00:00:00 2001 From: Tomasz Durda Date: Tue, 27 May 2025 08:28:07 +0200 Subject: [PATCH 2/2] Updated naming --- _src/enum-representations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_src/enum-representations.md b/_src/enum-representations.md index 848805c..5c4db5e 100644 --- a/_src/enum-representations.md +++ b/_src/enum-representations.md @@ -194,7 +194,7 @@ In case you want to disable the sequence format, you can use the ```rust #[derive(Debug, Serialize, Deserialize)] -#[serde(tag = "type", content = "x", seq=false)] +#[serde(tag = "type", content = "x", seq_form=false)] enum MyType { Topic(i64), Sidebar(i64) }