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

Add support for NonZeroI* types #1589

Merged
merged 2 commits into from Jul 28, 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
3 changes: 2 additions & 1 deletion serde/build.rs
Expand Up @@ -69,11 +69,12 @@ fn main() {
println!("cargo:rustc-cfg=num_nonzero");
}

// TryFrom and Atomic types stabilized in Rust 1.34:
// TryFrom, Atomic types, and non-zero signed integers stabilized in Rust 1.34:
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations
if minor >= 34 {
println!("cargo:rustc-cfg=core_try_from");
println!("cargo:rustc-cfg=num_nonzero_signed");

// Whitelist of archs that support std::sync::atomic module. Ideally we
// would use #[cfg(target_has_atomic = "...")] but it is not stable yet.
Expand Down
15 changes: 14 additions & 1 deletion serde/src/de/impls.rs
Expand Up @@ -2404,20 +2404,33 @@ macro_rules! nonzero_integers {
}

nonzero_integers! {
// Not including signed NonZeroI* since they might be removed
NonZeroU8,
NonZeroU16,
NonZeroU32,
NonZeroU64,
NonZeroUsize,
}

#[cfg(num_nonzero_signed)]
nonzero_integers! {
NonZeroI8,
NonZeroI16,
NonZeroI32,
NonZeroI64,
NonZeroIsize,
}

// Currently 128-bit integers do not work on Emscripten targets so we need an
// additional `#[cfg]`
serde_if_integer128! {
nonzero_integers! {
NonZeroU128,
}

#[cfg(num_nonzero_signed)]
nonzero_integers! {
NonZeroI128,
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 14 additions & 1 deletion serde/src/ser/impls.rs
Expand Up @@ -481,20 +481,33 @@ macro_rules! nonzero_integers {
}

nonzero_integers! {
// Not including signed NonZeroI* since they might be removed
NonZeroU8,
NonZeroU16,
NonZeroU32,
NonZeroU64,
NonZeroUsize,
}

#[cfg(num_nonzero_signed)]
nonzero_integers! {
NonZeroI8,
NonZeroI16,
NonZeroI32,
NonZeroI64,
NonZeroIsize,
}

// Currently 128-bit integers do not work on Emscripten targets so we need an
// additional `#[cfg]`
serde_if_integer128! {
nonzero_integers! {
NonZeroU128,
}

#[cfg(num_nonzero_signed)]
nonzero_integers! {
NonZeroI128,
}
}

impl<T> Serialize for Cell<T>
Expand Down