From 0f72d1a3888c14314133f56ea3b3617885a82338 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 10 Apr 2017 17:01:11 -0700 Subject: [PATCH] Put rc impls behind a cfg --- serde/Cargo.toml | 5 +++++ serde/src/de/impls.rs | 12 ++++++------ serde/src/ser/impls.rs | 12 ++++++------ travis.sh | 10 +++++----- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/serde/Cargo.toml b/serde/Cargo.toml index 0c3f0c3b..12020eeb 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -64,6 +64,11 @@ alloc = ["unstable"] # https://doc.rust-lang.org/collections/ collections = ["alloc"] +# Opt into impls for Rc and Arc. Serializing and deserializing these types +# 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 = [] + # Get serde_derive picked up by the Integer 32 playground. Not public API. # # http://play.integer32.com/ diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index ffe3291c..5416fab8 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -28,14 +28,14 @@ use std::ffi::{CString, OsString}; #[cfg(all(feature = "std", feature = "unstable"))] use std::ffi::CStr; -#[cfg(feature = "std")] +#[cfg(all(feature = "rc", feature = "std"))] use std::rc::Rc; -#[cfg(all(feature = "alloc", not(feature = "std")))] +#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))] use alloc::rc::Rc; -#[cfg(feature = "std")] +#[cfg(all(feature = "rc", feature = "std"))] use std::sync::Arc; -#[cfg(all(feature = "alloc", not(feature = "std")))] +#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))] use alloc::arc::Arc; #[cfg(all(feature = "alloc", not(feature = "std")))] @@ -1141,7 +1141,7 @@ impl<'de> Deserialize<'de> for Box { } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc { fn deserialize(deserializer: D) -> Result, D::Error> where D: Deserializer<'de> @@ -1151,7 +1151,7 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc { } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] impl<'de, T: Deserialize<'de>> Deserialize<'de> for Rc { fn deserialize(deserializer: D) -> Result, D::Error> where D: Deserializer<'de> diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index d0a74b97..e51a2999 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -17,16 +17,16 @@ use core::hash::{Hash, BuildHasher}; use std::{net, ops, path}; #[cfg(feature = "std")] use std::ffi::{CString, CStr, OsString, OsStr}; -#[cfg(feature = "std")] +#[cfg(all(feature = "rc", feature = "std"))] use std::rc::Rc; -#[cfg(all(feature = "alloc", not(feature = "std")))] +#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))] use alloc::rc::Rc; #[cfg(feature = "std")] use std::time::Duration; -#[cfg(feature = "std")] +#[cfg(all(feature = "rc", feature = "std"))] use std::sync::Arc; -#[cfg(all(feature = "alloc", not(feature = "std")))] +#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))] use alloc::arc::Arc; #[cfg(all(feature = "alloc", not(feature = "std")))] @@ -555,7 +555,7 @@ impl Serialize for Box } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] impl Serialize for Rc where T: Serialize { @@ -567,7 +567,7 @@ impl Serialize for Rc } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))] impl Serialize for Arc where T: Serialize { diff --git a/travis.sh b/travis.sh index a4023469..0f49838f 100755 --- a/travis.sh +++ b/travis.sh @@ -29,7 +29,7 @@ if [ -n "${CLIPPY}" ]; then fi cd "$DIR/serde" - cargo clippy --features unstable -- -Dclippy + cargo clippy --features 'rc unstable' -- -Dclippy cd "$DIR/serde_derive" cargo clippy --features unstable -- -Dclippy @@ -47,7 +47,7 @@ else channel build --no-default-features channel build --no-default-features --features alloc channel build --no-default-features --features collections - channel test --features unstable + channel test --features 'rc unstable' cd "$DIR/test_suite/deps" channel build cd "$DIR/test_suite" @@ -58,19 +58,19 @@ else CHANNEL=beta cargo clean cd "$DIR/serde" - channel build + channel build --features rc cd "$DIR/test_suite" channel test CHANNEL=stable cargo clean cd "$DIR/serde" - channel build + channel build --features rc channel build --no-default-features CHANNEL=1.13.0 cargo clean cd "$DIR/serde" - channel build + channel build --features rc channel build --no-default-features fi