Skip to content

Commit d7cd4e4

Browse files
committed
Added info about sequence enum representations
1 parent 9dfa6df commit d7cd4e4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

_src/enum-representations.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,47 @@ enum Data {
157157

158158
The `serde` crate's "alloc" Cargo feature must be enabled to deserialize an
159159
untagged tagged enum. (It is enabled by default.)
160+
161+
## Sequence format of the adjacently and internally tagged representations
162+
163+
Both the adjacently tagged and internally tagged representations can be
164+
expressed either via map or sequence syntax. For example:
165+
166+
```rust
167+
#[derive(Debug, Serialize, Deserialize)]
168+
#[serde(tag = "type", content = "x")]
169+
enum MyType {
170+
Topic(i64), Sidebar(i64)
171+
}
172+
173+
fn main() {}
174+
```
175+
176+
is equivalent to both
177+
178+
```json
179+
[ "Topic", 1 ]
180+
```
181+
182+
and
183+
184+
```json
185+
{ "type": "Topic", "x": 1 }
186+
```
187+
188+
### Disable the sequence format
189+
190+
*(since serde v1.1.0)*
191+
192+
In case you want to disable the sequence format, you can use the
193+
`#[serde(seq=false)]`.
194+
195+
```rust
196+
#[derive(Debug, Serialize, Deserialize)]
197+
#[serde(tag = "type", content = "x", seq=false)]
198+
enum MyType {
199+
Topic(i64), Sidebar(i64)
200+
}
201+
```
202+
203+
will casue the sequence syntax to be disabled.

0 commit comments

Comments
 (0)