From f197c3ce96470bba56885621d22b896cea5f5aa6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 5 Jun 2016 11:54:36 -0700 Subject: [PATCH] Readme for "bound" attribute --- README.md | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7af59589..03093081 100644 --- a/README.md +++ b/README.md @@ -688,12 +688,15 @@ how types are serialized. Here are the supported annotations: Container Annotations: -| Annotation | Function | -| ---------- | -------- | -| `#[serde(rename="name")]` | Serialize and deserialize this container with the given name | -| `#[serde(rename(serialize="name1"))]` | Serialize this container with the given name | -| `#[serde(rename(deserialize="name1"))]` | Deserialize this container with the given name | -| `#[serde(deny_unknown_fields)]` | Always error during serialization when encountering unknown fields. When absent, unknown fields are ignored for self-describing formats like JSON. | +| Annotation | Function | +| ---------- | -------- | +| `#[serde(rename="name")]` | Serialize and deserialize this container with the given name | +| `#[serde(rename(serialize="name1"))]` | Serialize this container with the given name | +| `#[serde(rename(deserialize="name1"))]` | Deserialize this container with the given name | +| `#[serde(deny_unknown_fields)]` | Always error during serialization when encountering unknown fields. When absent, unknown fields are ignored for self-describing formats like JSON. | +| `#[serde(bound="T: MyTrait")]` | Where-clause for the Serialize and Deserialize impls. This replaces any bounds inferred by Serde. | +| `#[serde(bound(serialize="T: MyTrait"))]` | Where-clause for the Serialize impl. | +| `#[serde(bound(deserialize="T: MyTrait"))]` | Where-clause for the Deserialize impl. | Variant Annotations: @@ -705,18 +708,21 @@ Variant Annotations: Field Annotations: -| Annotation | Function | -| ---------- | -------- | -| `#[serde(rename="name")]` | Serialize and deserialize this field with the given name | -| `#[serde(rename(serialize="name1"))]` | Serialize this field with the given name | -| `#[serde(rename(deserialize="name1"))]` | Deserialize this field with the given name | -| `#[serde(default)]` | If the value is not specified, use the `Default::default()` | -| `#[serde(default="$path")]` | Call the path to a function `fn() -> T` to build the value | -| `#[serde(skip_serializing)]` | Do not serialize this value | -| `#[serde(skip_deserializing)]` | Always use `Default::default()` or `#[serde(default="$path")]` instead of deserializing this value | -| `#[serde(skip_serializing_if="$path")]` | Do not serialize this value if this function `fn(&T) -> bool` returns `true` | -| `#[serde(serialize_with="$path")]` | Call a function `fn(&T, &mut S) -> Result<(), S::Error> where S: Serializer` to serialize this value of type `T` | -| `#[serde(deserialize_with="$path")]` | Call a function `fn(&mut D) -> Result where D: Deserializer` to deserialize this value of type `T` | +| Annotation | Function | +| ---------- | -------- | +| `#[serde(rename="name")]` | Serialize and deserialize this field with the given name | +| `#[serde(rename(serialize="name1"))]` | Serialize this field with the given name | +| `#[serde(rename(deserialize="name1"))]` | Deserialize this field with the given name | +| `#[serde(default)]` | If the value is not specified, use the `Default::default()` | +| `#[serde(default="$path")]` | Call the path to a function `fn() -> T` to build the value | +| `#[serde(skip_serializing)]` | Do not serialize this value | +| `#[serde(skip_deserializing)]` | Always use `Default::default()` or `#[serde(default="$path")]` instead of deserializing this value | +| `#[serde(skip_serializing_if="$path")]` | Do not serialize this value if this function `fn(&T) -> bool` returns `true` | +| `#[serde(serialize_with="$path")]` | Call a function `fn(&T, &mut S) -> Result<(), S::Error> where S: Serializer` to serialize this value of type `T` | +| `#[serde(deserialize_with="$path")]` | Call a function `fn(&mut D) -> Result where D: Deserializer` to deserialize this value of type `T` | +| `#[serde(bound="T: MyTrait")]` | Where-clause for the Serialize and Deserialize impls. This replaces any bounds inferred by Serde for the current field. | +| `#[serde(bound(serialize="T: MyTrait"))]` | Where-clause for the Serialize impl. | +| `#[serde(bound(deserialize="T: MyTrait"))]` | Where-clause for the Deserialize impl. | Using in `no_std` crates ========================