From a5262289c36021024bf389279af95b505011e63d Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Wed, 17 Apr 2019 15:44:32 +0800 Subject: [PATCH] Update rust-toolchain to nightly-2019-04-17 (#6) Signed-off-by: koushiro --- primitive-types/src/error.rs | 72 ------------------------------------ primitive-types/src/lib.rs | 16 ++++++-- primitive-types/src/tests.rs | 2 + rust-toolchain | 2 +- ustd/src/lib.rs | 4 +- 5 files changed, 18 insertions(+), 78 deletions(-) delete mode 100644 primitive-types/src/error.rs diff --git a/primitive-types/src/error.rs b/primitive-types/src/error.rs deleted file mode 100644 index 027149f..0000000 --- a/primitive-types/src/error.rs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2015-2019 Parity Technologies -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// TODO: Remove TryFrom and TryInto when Rust trait is stablized -// https://github.com/paritytech/parity-common/issues/103 -//! Error, `TryFrom` and `TryInto` trait, should be removed when standard library stablize those. - -/// Error type for conversion. -pub enum Error { - /// Overflow encountered. - Overflow, -} - -/// An attempted conversion that consumes `self`, which may or may not be -/// expensive. -/// -/// Library authors should not directly implement this trait, but should prefer -/// implementing the [`TryFrom`] trait, which offers greater flexibility and -/// provides an equivalent `TryInto` implementation for free, thanks to a -/// blanket implementation in the standard library. For more information on this, -/// see the documentation for [`Into`]. -/// -/// [`TryFrom`]: trait.TryFrom.html -/// [`Into`]: trait.Into.html -pub trait TryInto: Sized { - /// The type returned in the event of a conversion error. - type Error; - - /// Performs the conversion. - fn try_into(self) -> Result; -} - -/// Attempt to construct `Self` via a conversion. -pub trait TryFrom: Sized { - /// The type returned in the event of a conversion error. - type Error; - - /// Performs the conversion. - fn try_from(value: T) -> Result; -} - -// TryFrom implies TryInto -impl TryInto for T -where - U: TryFrom, -{ - type Error = U::Error; - - fn try_into(self) -> Result { - U::try_from(self) - } -} - -pub enum Never {} - -// Infallible conversions are semantically equivalent to fallible conversions -// with an uninhabited error type. -impl TryFrom for T -where - T: From, -{ - type Error = Never; - - fn try_from(value: U) -> Result { - Ok(T::from(value)) - } -} diff --git a/primitive-types/src/lib.rs b/primitive-types/src/lib.rs index d057043..91f8571 100644 --- a/primitive-types/src/lib.rs +++ b/primitive-types/src/lib.rs @@ -25,20 +25,30 @@ extern crate uint; #[macro_use] extern crate fixed_hash; +use ustd::convert::TryFrom; + +#[cfg(feature = "serde")] +pub use impl_serde::serde; #[cfg(feature = "serde")] use impl_serde::{impl_fixed_hash_serde, impl_uint_serde}; +#[cfg(feature = "codec")] +pub use impl_codec::codec; #[cfg(feature = "codec")] use impl_codec::{impl_fixed_hash_codec, impl_fixed_hash_codec_ext, impl_uint_codec}; +#[cfg(feature = "rlp")] +pub use impl_rlp::rlp; #[cfg(feature = "rlp")] use impl_rlp::{impl_fixed_hash_rlp, impl_uint_rlp}; -mod error; -#[cfg(test)] mod tests; -pub use self::error::{Error, Never, TryFrom, TryInto}; +/// Error type for conversion. +pub enum Error { + /// Overflow encountered. + Overflow, +} // ================================================================================================ // Unsigned Integer -- U64, U128, U256, U512. diff --git a/primitive-types/src/tests.rs b/primitive-types/src/tests.rs index 384416b..49a3feb 100644 --- a/primitive-types/src/tests.rs +++ b/primitive-types/src/tests.rs @@ -1,3 +1,5 @@ +#![cfg(test)] + #[cfg(any(feature = "serde", feature = "codec"))] macro_rules! from_low_u64_be { ($hash: ident, $val: expr) => {{ diff --git a/rust-toolchain b/rust-toolchain index 71b64c1..0a7fdc0 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2019-03-05 \ No newline at end of file +nightly-2019-04-17 \ No newline at end of file diff --git a/ustd/src/lib.rs b/ustd/src/lib.rs index 31c584b..caf7025 100644 --- a/ustd/src/lib.rs +++ b/ustd/src/lib.rs @@ -21,7 +21,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(core_intrinsics))] -#![cfg_attr(not(feature = "std"), feature(alloc))] +#![cfg_attr(not(feature = "std"), feature(alloc_prelude))] use cfg_if::cfg_if; @@ -32,7 +32,7 @@ cfg_if! { pub use alloc::boxed; pub use alloc::collections; pub use alloc::fmt as alloc_fmt; - pub use alloc::prelude as alloc_prelude; + pub use alloc::prelude::v1 as alloc_prelude; pub use alloc::rc; pub use alloc::string; pub use alloc::vec;