Skip to content

Commit

Permalink
Do not return DeError::Unsupported in SimpleTypeDeserializer, cal…
Browse files Browse the repository at this point in the history
…l `deserialize_str` instead

Deserializer methods are only hints, if deserializer could not satisfy
request, it should return the data that it has. It is responsibility
of a Visitor to return an error if it does not understand the data

UnitDeserializer::new() available only since serde 1.0.139 (serde-rs/serde#2246)
  • Loading branch information
Mingun committed Oct 28, 2023
1 parent 77e5a2c commit a5490f2
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -16,7 +16,7 @@ include = ["src/*", "LICENSE-MIT.md", "README.md"]
[dependencies]
document-features = { version = "0.2", optional = true }
encoding_rs = { version = "0.8", optional = true }
serde = { version = ">=1.0.100", optional = true }
serde = { version = ">=1.0.139", optional = true }
tokio = { version = "1.10", optional = true, default-features = false, features = ["io-util"] }
memchr = "2.1"
arbitrary = { version = "1", features = ["derive"], optional = true }
Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -16,6 +16,10 @@

### Misc Changes

- [#675]: Minimum supported version of serde raised to 1.0.139

[#675]: https://github.com/tafia/quick-xml/pull/675


## 0.31.0 -- 2023-10-22

Expand Down
26 changes: 16 additions & 10 deletions src/de/mod.rs
Expand Up @@ -509,8 +509,9 @@
//! /// Use unit variant, if you do not care of a content.
//! /// You can use tuple variant if you want to parse
//! /// textual content as an xs:list.
//! /// Struct variants are not supported and will return
//! /// Err(Unsupported)
//! /// Struct variants are will pass a string to the
//! /// struct enum variant visitor, which typically
//! /// returns Err(Custom)
//! #[serde(rename = "$text")]
//! Text(String),
//! }
Expand Down Expand Up @@ -613,8 +614,9 @@
//! /// Use unit variant, if you do not care of a content.
//! /// You can use tuple variant if you want to parse
//! /// textual content as an xs:list.
//! /// Struct variants are not supported and will return
//! /// Err(Unsupported)
//! /// Struct variants are will pass a string to the
//! /// struct enum variant visitor, which typically
//! /// returns Err(Custom)
//! #[serde(rename = "$text")]
//! Text(String),
//! }
Expand Down Expand Up @@ -1377,19 +1379,23 @@
//! |Kind |Top-level and in `$value` field |In normal field |In `$text` field |
//! |-------|-----------------------------------------|---------------------|---------------------|
//! |Unit |`<Unit/>` |`<field>Unit</field>`|`Unit` |
//! |Newtype|`<Newtype>42</Newtype>` |Err(Unsupported) |Err(Unsupported) |
//! |Tuple |`<Tuple>42</Tuple><Tuple>answer</Tuple>` |Err(Unsupported) |Err(Unsupported) |
//! |Struct |`<Struct><q>42</q><a>answer</a></Struct>`|Err(Unsupported) |Err(Unsupported) |
//! |Newtype|`<Newtype>42</Newtype>` |Err(Custom) [^0] |Err(Custom) [^0] |
//! |Tuple |`<Tuple>42</Tuple><Tuple>answer</Tuple>` |Err(Custom) [^0] |Err(Custom) [^0] |
//! |Struct |`<Struct><q>42</q><a>answer</a></Struct>`|Err(Custom) [^0] |Err(Custom) [^0] |
//!
//! `$text` enum variant
//! --------------------
//!
//! |Kind |Top-level and in `$value` field |In normal field |In `$text` field |
//! |-------|-----------------------------------------|---------------------|---------------------|
//! |Unit |_(empty)_ |`<field/>` |_(empty)_ |
//! |Newtype|`42` |Err(Unsupported) [^1]|Err(Unsupported) [^2]|
//! |Tuple |`42 answer` |Err(Unsupported) [^3]|Err(Unsupported) [^4]|
//! |Struct |Err(Unsupported) |Err(Unsupported) |Err(Unsupported) |
//! |Newtype|`42` |Err(Custom) [^0] [^1]|Err(Custom) [^0] [^2]|
//! |Tuple |`42 answer` |Err(Custom) [^0] [^3]|Err(Custom) [^0] [^4]|
//! |Struct |Err(Custom) [^0] |Err(Custom) [^0] |Err(Custom) [^0] |
//!
//! [^0]: Error is returned by the deserialized type. In case of derived implementation a `Custom`
//! error will be returned, but custom deserialize implementation can successfully deserialize
//! value from a string which will be passed to it.
//!
//! [^1]: If this serialize as `<field>42</field>` then it will be ambiguity during deserialization,
//! because it clash with `Unit` representation in normal field.
Expand Down

0 comments on commit a5490f2

Please sign in to comment.