Skip to content

Commit a75187f

Browse files
authored
Merge pull request #96 from tobz1000/master
Add missing attribute documentation
2 parents 229a737 + 4b6bb86 commit a75187f

File tree

3 files changed

+105
-19
lines changed

3 files changed

+105
-19
lines changed

_src/container-attrs.md

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
# Container attributes
22

33
- ##### `#[serde(rename = "name")]` {#rename}
4+
-- `#[serde(rename(serialize = "ser_name"))]`
5+
-- `#[serde(rename(deserialize = "de_name"))]`
6+
-- `#[serde(rename(serialize = "ser_name", deserialize = "de_name"))]`
47

58
Serialize and deserialize this struct or enum with the given name instead of
69
its Rust name.
710

11+
Also allows specifying an alternate name only when serializing, or only when
12+
deserializing, or different alternate names for serializing and deserializing.
13+
814
- ##### `#[serde(rename_all = "...")]` {#rename_all}
15+
-- `#[serde(rename_all(serialize = "..."))]`
16+
-- `#[serde(rename_all(deserialize = "..."))]`
17+
-- `#[serde(rename_all(serialize = "...", deserialize = "..."))]`
918

1019
Rename all the fields (if this is a struct) or variants (if this is an enum)
1120
according to the given case convention. The possible values are `"lowercase"`,
1221
`"UPPERCASE"`, `"PascalCase"`, `"camelCase"`, `"snake_case"`,
1322
`"SCREAMING_SNAKE_CASE"`, `"kebab-case"`, `"SCREAMING-KEBAB-CASE"`.
1423

24+
Also allows specifying a case convention only when serializing, or only when
25+
deserializing, or different case conventions for serializing and
26+
deserializing.
27+
1528
- ##### `#[serde(deny_unknown_fields)]` {#deny_unknown_fields}
1629

1730
Always error during deserialization when encountering unknown fields. When
@@ -36,17 +49,16 @@
3649
representations](enum-representations.md) for details on this representation.
3750

3851
- ##### `#[serde(bound = "T: MyTrait")]` {#bound}
52+
-- `#[serde(bound(serialize = "T: MySerTrait"))]` {#bound--serialize}
53+
-- `#[serde(bound(deserialize = "T: MyDeTrait"))]` {#bound--deserialize}
54+
-- `#[serde(bound(serialize = "T: MySerTrait", deserialize = "T: MyDeTrait"))]`
3955

40-
Where-clause for the `Serialize` and `Deserialize` impls. This replaces any
56+
Where-clause for the `Serialize` and/or `Deserialize` impls. This replaces any
4157
trait bounds inferred by Serde.
4258

43-
- ##### `#[serde(bound(serialize = "T: MyTrait"))]` {#bound--serialize}
44-
45-
Where-clause for the `Serialize` impl.
46-
47-
- ##### `#[serde(bound(deserialize = "T: MyTrait"))]` {#bound--deserialize}
48-
49-
Where-clause for the `Deserialize` impl.
59+
Allows specifying the same where-clause for serializing and deserializing; or
60+
only specifying a where-clause for serializing, or deserializing; or
61+
specifying different clauses for serializing and deserializing.
5062

5163
- ##### `#[serde(default)]` {#default}
5264

@@ -71,3 +83,45 @@
7183
Serialize and deserialize a newtype struct or a braced struct with one field
7284
exactly the same as if its one field were serialized and deserialized by
7385
itself. Analogous to `#[repr(transparent)]`.
86+
87+
- ##### `#[serde(crate = "...")]` {#crate}
88+
89+
Specify a path to the `serde` crate instance to use when deriving `Serialize`
90+
and/or `Deserialize` for this type.
91+
92+
- ##### `#[serde(from = "FromType")]` {#from}
93+
94+
Deserialize this type by deserializing into `FromType`, then converting. This
95+
type must implement `From<FromType>`, and `FromType` must implement
96+
`Deserialize`.
97+
98+
- ##### `#[serde(into = "IntoType")]` {#into}
99+
100+
Serialize this type by converting it into the specified `IntoType` and
101+
serializing that. This type must implement `Clone` and `Into<IntoType>`, and
102+
`IntoType` must implement `Serialize`.
103+
104+
- ##### `#[serde(field_identifier)]` {#field_identifier}
105+
106+
Denotes that this enum represents the field names of a struct type. Used when
107+
[manually implementing `Deserialize` for the struct
108+
type.](deserialize_struct.md)
109+
110+
This attribute is probably not useful if you are automatically deriving your
111+
own types.
112+
113+
Variants for the field_identifier enum may either all be units, or the last
114+
variant may be a newtype struct, which is selected when an unlisted field name
115+
is encountered during deserialization. Cannot be set if
116+
`#[serde(variant_identifier)]` is also set.
117+
118+
- ##### `#[serde(variant_identifier)]` {#variant_identifier}
119+
120+
Denotes that this enum represents the variant names of another enum type.
121+
Used when manually implementing `Deserialize` for the other enum type.
122+
123+
This attribute is probably not useful if you are automatically deriving your
124+
own types.
125+
126+
Only valid for enums where all variants are units. Cannot be set if
127+
`#[serde(field_identifier)]` is also set.

_src/field-attrs.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# Field attributes
22

33
- ##### `#[serde(rename = "name")]` {#rename}
4+
-- `#[serde(rename(serialize = "ser_name"))]`
5+
-- `#[serde(rename(deserialize = "de_name"))]`
6+
-- `#[serde(rename(serialize = "ser_name", deserialize = "de_name"))]`
47

5-
Serialize and deserialize this field with the given name instead of its Rust
6-
name. This is useful for [serializing fields as camelCase](attr-rename.md) or
7-
serializing fields with names that are reserved Rust keywords.
8+
Serialize and/or deserialize this field with the given name instead of its
9+
Rust name. This is useful for
10+
[serializing fields as camelCase](attr-rename.md) or serializing fields with
11+
names that are reserved Rust keywords.
12+
13+
Allows specifying the same given name for serializing and deserializing; or
14+
only specifying a given name for serializing, or for deserializing; or
15+
specifying different given names for serializing and deserializing.
816

917
- ##### `#[serde(alias = "name")]` {#alias}
1018

@@ -85,17 +93,16 @@
8593
deserialization. See [this example](lifetimes.md#borrowing-data-in-a-derived-impl).
8694

8795
- ##### `#[serde(bound = "T: MyTrait")]` {#bound}
96+
-- `#[serde(bound(serialize = "T: MySerTrait"))]` {#bound--serialize}
97+
-- `#[serde(bound(deserialize = "T: MyDeTrait"))]` {#bound--deserialize}
98+
-- `#[serde(bound(serialize = "T: MySerTrait", deserialize = "T: MyDeTrait"))]`
8899

89-
Where-clause for the `Serialize` and `Deserialize` impls. This replaces any
100+
Where-clause for the `Serialize` and/or `Deserialize` impls. This replaces any
90101
trait bounds inferred by Serde for the current field.
91102

92-
- ##### `#[serde(bound(serialize = "T: MyTrait"))]` {#bound--serialize}
93-
94-
Where-clause for the `Serialize` impl.
95-
96-
- ##### `#[serde(bound(deserialize = "T: MyTrait"))]` {#bound--deserialize}
97-
98-
Where-clause for the `Deserialize` impl.
103+
Allows specifying the same where-clause for serializing and deserializing; or
104+
only specifying a where-clause for serializing, or for deserializing; or
105+
specifying different clauses for serializing and deserializing.
99106

100107
- ##### `#[serde(getter = "...")]` {#getter}
101108

_src/variant-attrs.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
# Variant attributes
22

33
- ##### `#[serde(rename = "name")]` {#rename}
4+
-- `#[serde(rename(serialize = "ser_name"))]`
5+
-- `#[serde(rename(deserialize = "de_name"))]`
6+
-- `#[serde(rename(serialize = "ser_name", deserialize = "de_name"))]`
47

58
Serialize and deserialize this variant with the given name instead of its Rust
69
name.
710

11+
Also allows specifying an alternate name only when serializing, or only when
12+
deserializing, or different alternate names for serializing and deserializing.
13+
814
- ##### `#[serde(alias = "name")]` {#alias}
915

1016
Deserialize this variant from the given name *or* from its Rust name. May be
1117
repeated to specify multiple possible names for the same variant.
1218

1319
- ##### `#[serde(rename_all = "...")]` {#rename_all}
20+
-- `#[serde(rename_all(serialize = "..."))]`
21+
-- `#[serde(rename_all(deserialize = "..."))]`
22+
-- `#[serde(rename_all(serialize = "...", deserialize = "..."))]`
1423

1524
Rename all the fields of this struct variant according to the given case
1625
convention. The possible values are `"lowercase"`, `"UPPERCASE"`,
1726
`"PascalCase"`, `"camelCase"`, `"snake_case"`, `"SCREAMING_SNAKE_CASE"`,
1827
`"kebab-case"`, `"SCREAMING-KEBAB-CASE"`.
1928

29+
Also allows specifying a case convention only when serializing, or only when
30+
deserializing, or different case conventions for serializing and
31+
deserializing.
32+
2033
- ##### `#[serde(skip)]` {#skip}
2134

2235
Never serialize or deserialize this variant.
@@ -59,6 +72,18 @@
5972
`$module::serialize` as the `serialize_with` function and
6073
`$module::deserialize` as the `deserialize_with` function.
6174

75+
- ##### `#[serde(bound = "T: MyTrait")]` {#bound}
76+
-- `#[serde(bound(serialize = "T: MySerTrait"))]` {#bound--serialize}
77+
-- `#[serde(bound(deserialize = "T: MyDeTrait"))]` {#bound--deserialize}
78+
-- `#[serde(bound(serialize = "T: MySerTrait", deserialize = "T: MyDeTrait"))]`
79+
80+
Where-clause for the `Serialize` and/or `Deserialize` impls. This replaces any
81+
trait bounds inferred by Serde for the current variant.
82+
83+
Allows specifying the same where-clause for serializing and deserializing; or
84+
only specifying a where-clause for serializing, or for deserializing; or
85+
specifying different clauses for serializing and deserializing.
86+
6287
- ##### `#[serde(borrow)]` and `#[serde(borrow = "'a + 'b + ...")]` {#borrow}
6388

6489
Borrow data for this field from the deserializer by using zero-copy

0 commit comments

Comments
 (0)