Merge pull request #864 from serde-rs/rc

Put rc impls behind a cfg
This commit is contained in:
David Tolnay 2017-04-10 17:20:38 -07:00 committed by GitHub
commit ab82f09e5d
4 changed files with 22 additions and 17 deletions

View File

@ -64,6 +64,11 @@ alloc = ["unstable"]
# https://doc.rust-lang.org/collections/ # https://doc.rust-lang.org/collections/
collections = ["alloc"] collections = ["alloc"]
# Opt into impls for Rc<T> and Arc<T>. 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. # Get serde_derive picked up by the Integer 32 playground. Not public API.
# #
# http://play.integer32.com/ # http://play.integer32.com/

View File

@ -28,14 +28,14 @@ use std::ffi::{CString, OsString};
#[cfg(all(feature = "std", feature = "unstable"))] #[cfg(all(feature = "std", feature = "unstable"))]
use std::ffi::CStr; use std::ffi::CStr;
#[cfg(feature = "std")] #[cfg(all(feature = "rc", feature = "std"))]
use std::rc::Rc; use std::rc::Rc;
#[cfg(all(feature = "alloc", not(feature = "std")))] #[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
use alloc::rc::Rc; use alloc::rc::Rc;
#[cfg(feature = "std")] #[cfg(all(feature = "rc", feature = "std"))]
use std::sync::Arc; use std::sync::Arc;
#[cfg(all(feature = "alloc", not(feature = "std")))] #[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
use alloc::arc::Arc; use alloc::arc::Arc;
#[cfg(all(feature = "alloc", not(feature = "std")))] #[cfg(all(feature = "alloc", not(feature = "std")))]
@ -1141,7 +1141,7 @@ impl<'de> Deserialize<'de> for Box<str> {
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T> { impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T> {
fn deserialize<D>(deserializer: D) -> Result<Arc<T>, D::Error> fn deserialize<D>(deserializer: D) -> Result<Arc<T>, D::Error>
where D: Deserializer<'de> where D: Deserializer<'de>
@ -1151,7 +1151,7 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T> {
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Rc<T> { impl<'de, T: Deserialize<'de>> Deserialize<'de> for Rc<T> {
fn deserialize<D>(deserializer: D) -> Result<Rc<T>, D::Error> fn deserialize<D>(deserializer: D) -> Result<Rc<T>, D::Error>
where D: Deserializer<'de> where D: Deserializer<'de>

View File

@ -17,16 +17,16 @@ use core::hash::{Hash, BuildHasher};
use std::{net, ops, path}; use std::{net, ops, path};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::ffi::{CString, CStr, OsString, OsStr}; use std::ffi::{CString, CStr, OsString, OsStr};
#[cfg(feature = "std")] #[cfg(all(feature = "rc", feature = "std"))]
use std::rc::Rc; use std::rc::Rc;
#[cfg(all(feature = "alloc", not(feature = "std")))] #[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
use alloc::rc::Rc; use alloc::rc::Rc;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::time::Duration; use std::time::Duration;
#[cfg(feature = "std")] #[cfg(all(feature = "rc", feature = "std"))]
use std::sync::Arc; use std::sync::Arc;
#[cfg(all(feature = "alloc", not(feature = "std")))] #[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
use alloc::arc::Arc; use alloc::arc::Arc;
#[cfg(all(feature = "alloc", not(feature = "std")))] #[cfg(all(feature = "alloc", not(feature = "std")))]
@ -555,7 +555,7 @@ impl<T: ?Sized> Serialize for Box<T>
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<T> Serialize for Rc<T> impl<T> Serialize for Rc<T>
where T: Serialize where T: Serialize
{ {
@ -567,7 +567,7 @@ impl<T> Serialize for Rc<T>
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<T> Serialize for Arc<T> impl<T> Serialize for Arc<T>
where T: Serialize where T: Serialize
{ {

View File

@ -29,7 +29,7 @@ if [ -n "${CLIPPY}" ]; then
fi fi
cd "$DIR/serde" cd "$DIR/serde"
cargo clippy --features unstable -- -Dclippy cargo clippy --features 'rc unstable' -- -Dclippy
cd "$DIR/serde_derive" cd "$DIR/serde_derive"
cargo clippy --features unstable -- -Dclippy cargo clippy --features unstable -- -Dclippy
@ -47,7 +47,7 @@ else
channel build --no-default-features channel build --no-default-features
channel build --no-default-features --features alloc channel build --no-default-features --features alloc
channel build --no-default-features --features collections channel build --no-default-features --features collections
channel test --features unstable channel test --features 'rc unstable'
cd "$DIR/test_suite/deps" cd "$DIR/test_suite/deps"
channel build channel build
cd "$DIR/test_suite" cd "$DIR/test_suite"
@ -58,19 +58,19 @@ else
CHANNEL=beta CHANNEL=beta
cargo clean cargo clean
cd "$DIR/serde" cd "$DIR/serde"
channel build channel build --features rc
cd "$DIR/test_suite" cd "$DIR/test_suite"
channel test channel test
CHANNEL=stable CHANNEL=stable
cargo clean cargo clean
cd "$DIR/serde" cd "$DIR/serde"
channel build channel build --features rc
channel build --no-default-features channel build --no-default-features
CHANNEL=1.13.0 CHANNEL=1.13.0
cargo clean cargo clean
cd "$DIR/serde" cd "$DIR/serde"
channel build channel build --features rc
channel build --no-default-features channel build --no-default-features
fi fi