Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Serialize and Deserialize for core::cmp::Reverse #1486

Merged
merged 2 commits into from Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions serde/build.rs
Expand Up @@ -23,6 +23,12 @@ fn main() {
println!("cargo:rustc-cfg=collections_bound");
}

// core::cmp::Reverse stabilized in Rust 1.19:
// https://doc.rust-lang.org/stable/core/cmp/struct.Reverse.html
if minor >= 19 {
println!("cargo:rustc-cfg=core_reverse");
}

// CString::into_boxed_c_str stabilized in Rust 1.20:
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
if minor >= 20 {
Expand Down
3 changes: 3 additions & 0 deletions serde/src/de/impls.rs
Expand Up @@ -578,6 +578,9 @@ macro_rules! forwarded_impl {
#[cfg(all(feature = "std", de_boxed_c_str))]
forwarded_impl!((), Box<CStr>, CString::into_boxed_c_str);

#[cfg(core_reverse)]
forwarded_impl!((T), Reverse<T>, Reverse);

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

struct OptionVisitor<T> {
Expand Down
2 changes: 2 additions & 0 deletions serde/src/lib.rs
Expand Up @@ -139,6 +139,8 @@ mod lib {

pub use self::core::cell::{Cell, RefCell};
pub use self::core::clone::{self, Clone};
#[cfg(core_reverse)]
pub use self::core::cmp::Reverse;
pub use self::core::convert::{self, From, Into};
pub use self::core::default::{self, Default};
pub use self::core::fmt::{self, Debug, Display};
Expand Down
14 changes: 14 additions & 0 deletions serde/src/ser/impls.rs
Expand Up @@ -824,3 +824,17 @@ where
self.0.serialize(serializer)
}
}

#[cfg(core_reverse)]
impl<T> Serialize for Reverse<T>
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}