|
1 | 1 | # Container attributes
|
2 | 2 |
|
3 | 3 | - ##### `#[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"))]` |
4 | 7 |
|
5 | 8 | Serialize and deserialize this struct or enum with the given name instead of
|
6 | 9 | its Rust name.
|
7 | 10 |
|
| 11 | + Also allows specifying an alternate name only when serializing, or only when |
| 12 | + deserializing, or different alternate names for serializing and deserializing. |
| 13 | + |
8 | 14 | - ##### `#[serde(rename_all = "...")]` {#rename_all}
|
| 15 | +-- `#[serde(rename_all(serialize = "..."))]` |
| 16 | +-- `#[serde(rename_all(deserialize = "..."))]` |
| 17 | +-- `#[serde(rename_all(serialize = "...", deserialize = "..."))]` |
9 | 18 |
|
10 | 19 | Rename all the fields (if this is a struct) or variants (if this is an enum)
|
11 | 20 | according to the given case convention. The possible values are `"lowercase"`,
|
12 | 21 | `"UPPERCASE"`, `"PascalCase"`, `"camelCase"`, `"snake_case"`,
|
13 | 22 | `"SCREAMING_SNAKE_CASE"`, `"kebab-case"`, `"SCREAMING-KEBAB-CASE"`.
|
14 | 23 |
|
| 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 | + |
15 | 28 | - ##### `#[serde(deny_unknown_fields)]` {#deny_unknown_fields}
|
16 | 29 |
|
17 | 30 | Always error during deserialization when encountering unknown fields. When
|
|
36 | 49 | representations](enum-representations.md) for details on this representation.
|
37 | 50 |
|
38 | 51 | - ##### `#[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"))]` |
39 | 55 |
|
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 |
41 | 57 | trait bounds inferred by Serde.
|
42 | 58 |
|
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. |
50 | 62 |
|
51 | 63 | - ##### `#[serde(default)]` {#default}
|
52 | 64 |
|
|
71 | 83 | Serialize and deserialize a newtype struct or a braced struct with one field
|
72 | 84 | exactly the same as if its one field were serialized and deserialized by
|
73 | 85 | 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. |
0 commit comments