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

Bump rust toolchain to 2018-03-24. #20589

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Attempt to fix nonzero.

  • Loading branch information
mrowqa committed Apr 8, 2018
commit 261696e60073808c5cf25b34ed1abde6a9275e08
@@ -5,72 +5,14 @@
//! `NonZero*` types that are either `core::nonzero::NonZero<_>`
//! or some stable types with an equivalent API (but no memory layout optimization).

#![cfg_attr(feature = "unstable", feature(nonzero))]
#![cfg_attr(feature = "unstable", feature(const_fn))]
#![cfg_attr(feature = "unstable", feature(const_nonzero_new))]

#[cfg_attr(not(feature = "unstable"), macro_use)]
#[macro_use]
extern crate serde;
//extern crate serde_derive;

pub use imp::*;

#[cfg(feature = "unstable")]
mod imp {
extern crate core;
use self::core::nonzero::NonZero as CoreNonZero;
use serde::{Serialize, Serializer, Deserialize, Deserializer};

pub use self::core::nonzero::Zeroable;

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NonZero<T: Zeroable>(CoreNonZero<T>);

impl<T: Zeroable> NonZero<T> {
#[inline]
pub const unsafe fn new_unchecked(x: T) -> Self {
NonZero(CoreNonZero::new_unchecked(x))
}

#[inline]
pub fn new(x: T) -> Option<Self> {
CoreNonZero::new(x).map(NonZero)
}

#[inline]
pub fn get(self) -> T {
self.0.get()
}
}

// Not using derive because of the additional Clone bound required by the inner impl

impl<T> Serialize for NonZero<T>
where
T: Serialize + Zeroable + Clone,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}

impl<'de, T> Deserialize<'de> for NonZero<T>
where
T: Deserialize<'de> + Zeroable,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
CoreNonZero::deserialize(deserializer).map(NonZero)
}
}
}

#[cfg(not(feature = "unstable"))]
mod imp {
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct NonZero<T: Zeroable>(T);

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.