From 97cf40a8f748a5969c903e8f3692e6d9e5377804 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 5 Sep 2023 10:43:15 -0500 Subject: [PATCH 1/2] Help untagged users discover expecting --- _src/container-attrs.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_src/container-attrs.md b/_src/container-attrs.md index 89bce857..a76f777a 100644 --- a/_src/container-attrs.md +++ b/_src/container-attrs.md @@ -56,6 +56,8 @@ Use the untagged enum representation for this enum. See [enum representations](enum-representations.md) for details on this representation. + When no variant matches, the error may be uninformative which can be improved with [`serde(expecting)`](#expecting). + - ##### `#[serde(bound = "T: MyTrait")]` {#bound} Where-clause for the `Serialize` and `Deserialize` impls. This replaces any From a661bd1785d9cca17f6094c9d3e128e03567a224 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 5 Sep 2023 10:43:32 -0500 Subject: [PATCH 2/2] Help untagged users know of performance issues and fix them Inspired by serde-rs/serde#2101 --- _src/container-attrs.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/_src/container-attrs.md b/_src/container-attrs.md index a76f777a..6de6da0a 100644 --- a/_src/container-attrs.md +++ b/_src/container-attrs.md @@ -58,6 +58,9 @@ When no variant matches, the error may be uninformative which can be improved with [`serde(expecting)`](#expecting). + In performance-critical code, checking each variant and processing the errors can be slow. + In these cases, it may be better to hand-implement the deserialize trait for which [serde-untagged] may help. + - ##### `#[serde(bound = "T: MyTrait")]` {#bound} Where-clause for the `Serialize` and `Deserialize` impls. This replaces any @@ -122,3 +125,5 @@ Specify a custom type expectation text for deserialization error messages. This is used by the generated `expecting` method for the container `Visitor`, and as a fallthrough error message for untagged enums. + +[serde-untagged]: https://docs.rs/serde-untagged