mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-19 04:11:02 +00:00
Fix compatibility issues with syntax and Bound
This commit is contained in:
@@ -14,6 +14,15 @@ fn main() {
|
|||||||
let target = env::var("TARGET").unwrap();
|
let target = env::var("TARGET").unwrap();
|
||||||
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
|
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
|
||||||
|
|
||||||
|
// std::collections::Bound was stabilized in Rust 1.17
|
||||||
|
// but it was moved to core::ops later in Rust 1.26:
|
||||||
|
// https://doc.rust-lang.org/core/ops/enum.Bound.html
|
||||||
|
if minor >= 26 {
|
||||||
|
println!("cargo:rustc-cfg=ops_bound");
|
||||||
|
} else if minor >= 17 && cfg!(feature = "std") {
|
||||||
|
println!("cargo:rustc-cfg=collections_bound");
|
||||||
|
}
|
||||||
|
|
||||||
// CString::into_boxed_c_str stabilized in Rust 1.20:
|
// 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
|
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
|
||||||
if minor >= 20 {
|
if minor >= 20 {
|
||||||
@@ -42,6 +51,12 @@ fn main() {
|
|||||||
println!("cargo:rustc-cfg=integer128");
|
println!("cargo:rustc-cfg=integer128");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RangeToInclusive was stabilized in Rust 1.26:
|
||||||
|
// https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.html
|
||||||
|
if minor >= 26 {
|
||||||
|
println!("cargo:rustc-cfg=range_to_inclusive");
|
||||||
|
}
|
||||||
|
|
||||||
// Inclusive ranges methods stabilized in Rust 1.27:
|
// Inclusive ranges methods stabilized in Rust 1.27:
|
||||||
// https://github.com/rust-lang/rust/pull/50758
|
// https://github.com/rust-lang/rust/pull/50758
|
||||||
if minor >= 27 {
|
if minor >= 27 {
|
||||||
|
|||||||
@@ -2153,7 +2153,7 @@ where
|
|||||||
range::UnboundedRangeVisitor {
|
range::UnboundedRangeVisitor {
|
||||||
expecting: "struct RangeFrom",
|
expecting: "struct RangeFrom",
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
field,
|
field: field,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
Ok(start..)
|
Ok(start..)
|
||||||
@@ -2175,13 +2175,14 @@ where
|
|||||||
range::UnboundedRangeVisitor {
|
range::UnboundedRangeVisitor {
|
||||||
expecting: "struct RangeTo",
|
expecting: "struct RangeTo",
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
field,
|
field: field,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
Ok(..end)
|
Ok(..end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(range_to_inclusive)]
|
||||||
impl<'de, Idx> Deserialize<'de> for RangeToInclusive<Idx>
|
impl<'de, Idx> Deserialize<'de> for RangeToInclusive<Idx>
|
||||||
where
|
where
|
||||||
Idx: Deserialize<'de>,
|
Idx: Deserialize<'de>,
|
||||||
@@ -2197,10 +2198,10 @@ where
|
|||||||
range::UnboundedRangeVisitor {
|
range::UnboundedRangeVisitor {
|
||||||
expecting: "struct RangeToInclusive",
|
expecting: "struct RangeToInclusive",
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
field,
|
field: field,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
Ok(..=end)
|
Ok(RangeToInclusive { end: end })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2226,14 +2227,14 @@ mod range {
|
|||||||
|
|
||||||
impl Field {
|
impl Field {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
match self {
|
match *self {
|
||||||
Field::Start => "start",
|
Field::Start => "start",
|
||||||
Field::End => "end",
|
Field::End => "end",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name_slice(&self) -> &'static [&'static str] {
|
pub fn name_slice(&self) -> &'static [&'static str] {
|
||||||
match self {
|
match *self {
|
||||||
Field::Start => FIELDS_START_ONLY,
|
Field::Start => FIELDS_START_ONLY,
|
||||||
Field::End => FIELD_END_ONLY,
|
Field::End => FIELD_END_ONLY,
|
||||||
}
|
}
|
||||||
@@ -2411,6 +2412,7 @@ mod range {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(any(ops_bound, collections_bound))]
|
||||||
impl<'de, T> Deserialize<'de> for Bound<T>
|
impl<'de, T> Deserialize<'de> for Bound<T>
|
||||||
where
|
where
|
||||||
T: Deserialize<'de>
|
T: Deserialize<'de>
|
||||||
|
|||||||
+10
-1
@@ -160,7 +160,7 @@ mod lib {
|
|||||||
pub use self::core::default::{self, Default};
|
pub use self::core::default::{self, Default};
|
||||||
pub use self::core::fmt::{self, Debug, Display};
|
pub use self::core::fmt::{self, Debug, Display};
|
||||||
pub use self::core::marker::{self, PhantomData};
|
pub use self::core::marker::{self, PhantomData};
|
||||||
pub use self::core::ops::{Range, Bound, RangeFrom, RangeTo, RangeToInclusive};
|
pub use self::core::ops::{Range, RangeFrom, RangeTo};
|
||||||
pub use self::core::option::{self, Option};
|
pub use self::core::option::{self, Option};
|
||||||
pub use self::core::result::{self, Result};
|
pub use self::core::result::{self, Result};
|
||||||
|
|
||||||
@@ -224,6 +224,15 @@ mod lib {
|
|||||||
|
|
||||||
#[cfg(range_inclusive)]
|
#[cfg(range_inclusive)]
|
||||||
pub use self::core::ops::RangeInclusive;
|
pub use self::core::ops::RangeInclusive;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "std", collections_bound))]
|
||||||
|
pub use std::collections::Bound;
|
||||||
|
|
||||||
|
#[cfg(ops_bound)]
|
||||||
|
pub use self::core::ops::Bound;
|
||||||
|
|
||||||
|
#[cfg(range_to_inclusive)]
|
||||||
|
pub use self::core::ops::RangeToInclusive;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#[cfg(range_to_inclusive)]
|
||||||
impl<Idx> Serialize for RangeToInclusive<Idx>
|
impl<Idx> Serialize for RangeToInclusive<Idx>
|
||||||
where
|
where
|
||||||
Idx: Serialize,
|
Idx: Serialize,
|
||||||
@@ -307,6 +307,7 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(any(ops_bound, collections_bound))]
|
||||||
impl<T> Serialize for Bound<T>
|
impl<T> Serialize for Bound<T>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
|
|||||||
Reference in New Issue
Block a user