Merge pull request #1278 from SimonSapin/stable-nonzero
Implement for std::num::NonZero* on Rust 1.28+
This commit is contained in:
commit
039ebc63a1
@ -38,4 +38,10 @@ fn main() {
|
|||||||
if minor >= 26 {
|
if minor >= 26 {
|
||||||
println!("cargo:rustc-cfg=integer128");
|
println!("cargo:rustc-cfg=integer128");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Non-zero integers stabilized in Rust 1.28:
|
||||||
|
// https://github.com/rust-lang/rust/pull/50808
|
||||||
|
if minor >= 28 {
|
||||||
|
println!("cargo:rustc-cfg=num_nonzero");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2007,16 +2007,16 @@ where
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! nonzero_integers {
|
macro_rules! nonzero_integers {
|
||||||
( $( $T: ty, )+ ) => {
|
( $( $T: ident, )+ ) => {
|
||||||
$(
|
$(
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(num_nonzero)]
|
||||||
impl<'de> Deserialize<'de> for $T {
|
impl<'de> Deserialize<'de> for num::$T {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let value = try!(Deserialize::deserialize(deserializer));
|
let value = try!(Deserialize::deserialize(deserializer));
|
||||||
match <$T>::new(value) {
|
match <num::$T>::new(value) {
|
||||||
Some(nonzero) => Ok(nonzero),
|
Some(nonzero) => Ok(nonzero),
|
||||||
None => Err(Error::custom("expected a non-zero value")),
|
None => Err(Error::custom("expected a non-zero value")),
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ mod lib {
|
|||||||
pub use std::*;
|
pub use std::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use self::core::{cmp, iter, mem, ops, slice, str};
|
pub use self::core::{cmp, iter, mem, num, ops, slice, str};
|
||||||
pub use self::core::{f32, f64};
|
pub use self::core::{f32, f64};
|
||||||
pub use self::core::{i16, i32, i64, i8, isize};
|
pub use self::core::{i16, i32, i64, i8, isize};
|
||||||
pub use self::core::{u16, u32, u64, u8, usize};
|
pub use self::core::{u16, u32, u64, u8, usize};
|
||||||
@ -212,9 +212,6 @@ mod lib {
|
|||||||
pub use std::sync::{Mutex, RwLock};
|
pub use std::sync::{Mutex, RwLock};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
pub use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
pub use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -411,8 +411,8 @@ where
|
|||||||
macro_rules! nonzero_integers {
|
macro_rules! nonzero_integers {
|
||||||
( $( $T: ident, )+ ) => {
|
( $( $T: ident, )+ ) => {
|
||||||
$(
|
$(
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(num_nonzero)]
|
||||||
impl Serialize for $T {
|
impl Serialize for num::$T {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user