Merge pull request #1486 from vorot93/reverse

impl Serialize and Deserialize for core::cmp::Reverse
This commit is contained in:
David Tolnay 2019-02-28 16:39:54 -08:00 committed by GitHub
commit 97920be33a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View File

@ -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 {

View File

@ -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> {

View File

@ -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};

View File

@ -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)
}
}