Skip to content

Commit

Permalink
Add result feature to serde and serde_core
Browse files Browse the repository at this point in the history
  • Loading branch information
osiewicz committed Aug 5, 2024
1 parent 6d6ca71 commit 67b0a95
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions serde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ doc-scrape-examples = false
features = ["derive", "rc"]

[package.metadata.docs.rs]
features = ["derive", "rc", "unstable"]
features = ["derive", "rc", "result", "unstable"]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]

Expand All @@ -44,7 +44,7 @@ serde_derive = { version = "=1.0.204", path = "../serde_derive" }
### FEATURES #################################################################

[features]
default = ["std"]
default = ["std", "result"]

# Provide derive(Serialize, Deserialize) macros.
derive = ["serde_derive"]
Expand All @@ -68,3 +68,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<T, E>. 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"]
7 changes: 6 additions & 1 deletion serde_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
### FEATURES #################################################################

[features]
default = ["std"]
default = ["std", "result"]


# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
Expand All @@ -56,3 +56,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<T, E>. 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 = []
2 changes: 2 additions & 0 deletions serde_core/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,8 @@ where

////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "result")]
#[cfg_attr(docsrs, doc(cfg(feature = "result")))]
impl<'de, T, E> Deserialize<'de> for Result<T, E>
where
T: Deserialize<'de>,
Expand Down
2 changes: 2 additions & 0 deletions serde_core/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ where

////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "result")]
#[cfg_attr(docsrs, doc(cfg(feature = "result")))]
impl<T, E> Serialize for Result<T, E>
where
T: Serialize,
Expand Down

0 comments on commit 67b0a95

Please sign in to comment.