Skip to content

Commit 8f002ae

Browse files
committed
review: Gate Result impls behind a feature gate
1 parent 01de78b commit 8f002ae

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

serde/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ serde_derive = { version = "1", optional = true, path = "../serde_derive" }
2222
serde_derive = { version = "1", path = "../serde_derive" }
2323

2424
[package.metadata.playground]
25-
features = ["derive", "rc"]
25+
features = ["derive", "rc", "result"]
2626

2727
[package.metadata.docs.rs]
28-
features = ["derive", "rc", "unstable"]
28+
features = ["derive", "rc", "result", "unstable"]
2929
targets = ["x86_64-unknown-linux-gnu"]
3030
rustdoc-args = [
3131
"--generate-link-to-definition",
@@ -46,7 +46,7 @@ serde_derive = { version = "=1.0.219", path = "../serde_derive" }
4646
### FEATURES #################################################################
4747

4848
[features]
49-
default = ["std"]
49+
default = ["std", "result"]
5050

5151
# Provide derive(Serialize, Deserialize) macros.
5252
derive = ["serde_derive"]
@@ -70,3 +70,8 @@ alloc = ["serde_core/alloc"]
7070
# does not preserve identity and may result in multiple copies of the same data.
7171
# Be sure that this is what you want before enabling this feature.
7272
rc = ["serde_core/rc"]
73+
74+
# Provide impls for Result<T, E>. Enabling these impls allows for serialization
75+
# and deserialization of Result types, which may be useful in certain contexts
76+
# but could lead to confusion if ? or unwrap are overused.
77+
result = ["serde_core/result"]

serde_core/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ rust-version = "1.56"
1818
serde = { version = "1", path = "../serde" }
1919

2020
[package.metadata.playground]
21-
features = ["rc"]
21+
features = ["rc", "result"]
2222

2323
[package.metadata.docs.rs]
24-
features = ["rc", "unstable"]
24+
features = ["rc", "result", "unstable"]
2525
targets = ["x86_64-unknown-linux-gnu"]
2626
rustdoc-args = [
2727
"--generate-link-to-definition",
@@ -34,7 +34,7 @@ rustdoc-args = [
3434
### FEATURES #################################################################
3535

3636
[features]
37-
default = ["std"]
37+
default = ["std", "result"]
3838

3939
# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
4040
# Requires a dependency on the Rust standard library.
@@ -55,3 +55,8 @@ alloc = []
5555
# does not preserve identity and may result in multiple copies of the same data.
5656
# Be sure that this is what you want before enabling this feature.
5757
rc = []
58+
59+
# Provide impls for Result<T, E>. Enabling these impls allows for serialization
60+
# and deserialization of Result types, which may be useful in certain contexts
61+
# but could lead to confusion if ? or unwrap are overused.
62+
result = []

serde_core/src/de/impls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,6 +2975,8 @@ where
29752975

29762976
////////////////////////////////////////////////////////////////////////////////
29772977

2978+
#[cfg(feature = "result")]
2979+
#[cfg_attr(docsrs, doc(cfg(feature = "result")))]
29782980
impl<'de, T, E> Deserialize<'de> for Result<T, E>
29792981
where
29802982
T: Deserialize<'de>,

serde_core/src/ser/impls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,8 @@ where
660660

661661
////////////////////////////////////////////////////////////////////////////////
662662

663+
#[cfg(feature = "result")]
664+
#[cfg_attr(docsrs, doc(cfg(feature = "result")))]
663665
impl<T, E> Serialize for Result<T, E>
664666
where
665667
T: Serialize,

0 commit comments

Comments
 (0)