diff --git a/serde/Cargo.toml b/serde/Cargo.toml index ee707171..9dff8d8b 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -22,10 +22,10 @@ serde_derive = { version = "1", optional = true, path = "../serde_derive" } serde_derive = { version = "1", path = "../serde_derive" } [package.metadata.playground] -features = ["derive", "rc"] +features = ["derive", "rc", "result"] [package.metadata.docs.rs] -features = ["derive", "rc", "unstable"] +features = ["derive", "rc", "result", "unstable"] targets = ["x86_64-unknown-linux-gnu"] rustdoc-args = [ "--generate-link-to-definition", @@ -46,7 +46,7 @@ serde_derive = { version = "=1.0.219", path = "../serde_derive" } ### FEATURES ################################################################# [features] -default = ["std"] +default = ["std", "result"] # Provide derive(Serialize, Deserialize) macros. derive = ["serde_derive"] @@ -70,3 +70,8 @@ alloc = ["serde_core/alloc"] # does not preserve identity and may result in multiple copies of the same data. # Be sure that this is what you want before enabling this feature. rc = ["serde_core/rc"] + +# Provide impls for Result. Enabling these impls allows for serialization +# and deserialization of Result types, which may be useful in certain contexts +# but could lead to confusion if ? or unwrap are overused. +result = ["serde_core/result"] diff --git a/serde_core/Cargo.toml b/serde_core/Cargo.toml index 5e588dfd..a2245b55 100644 --- a/serde_core/Cargo.toml +++ b/serde_core/Cargo.toml @@ -18,10 +18,10 @@ rust-version = "1.56" serde = { version = "1", path = "../serde" } [package.metadata.playground] -features = ["rc"] +features = ["rc", "result"] [package.metadata.docs.rs] -features = ["rc", "unstable"] +features = ["rc", "result", "unstable"] targets = ["x86_64-unknown-linux-gnu"] rustdoc-args = [ "--generate-link-to-definition", @@ -34,7 +34,7 @@ rustdoc-args = [ ### FEATURES ################################################################# [features] -default = ["std"] +default = ["std", "result"] # Provide impls for common standard library types like Vec and HashMap. # Requires a dependency on the Rust standard library. @@ -55,3 +55,8 @@ alloc = [] # does not preserve identity and may result in multiple copies of the same data. # Be sure that this is what you want before enabling this feature. rc = [] + +# Provide impls for Result. Enabling these impls allows for serialization +# and deserialization of Result types, which may be useful in certain contexts +# but could lead to confusion if ? or unwrap are overused. +result = [] diff --git a/serde_core/src/de/impls.rs b/serde_core/src/de/impls.rs index ff25334c..7f1962ff 100644 --- a/serde_core/src/de/impls.rs +++ b/serde_core/src/de/impls.rs @@ -2975,6 +2975,8 @@ where //////////////////////////////////////////////////////////////////////////////// +#[cfg(feature = "result")] +#[cfg_attr(docsrs, doc(cfg(feature = "result")))] impl<'de, T, E> Deserialize<'de> for Result where T: Deserialize<'de>, diff --git a/serde_core/src/ser/impls.rs b/serde_core/src/ser/impls.rs index 930f0b88..a7a175db 100644 --- a/serde_core/src/ser/impls.rs +++ b/serde_core/src/ser/impls.rs @@ -660,6 +660,8 @@ where //////////////////////////////////////////////////////////////////////////////// +#[cfg(feature = "result")] +#[cfg_attr(docsrs, doc(cfg(feature = "result")))] impl Serialize for Result where T: Serialize,