diff --git a/primitive-types/src/error.rs b/primitive-types/src/error.rs deleted file mode 100644 index 298fc14ed..000000000 --- a/primitive-types/src/error.rs +++ /dev/null @@ -1,67 +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 93e1061b0..d0e2e3cef 100644 --- a/primitive-types/src/lib.rs +++ b/primitive-types/src/lib.rs @@ -14,9 +14,8 @@ #![cfg_attr(not(feature = "std"), no_std)] -mod error; - -pub use error::{Error, TryFrom, TryInto, Never}; +#[cfg(feature = "std")] +extern crate core; #[macro_use] extern crate uint; @@ -36,6 +35,14 @@ extern crate impl_codec; #[macro_use] extern crate impl_rlp; +use core::convert::TryFrom; + +/// Error type for conversion. +pub enum Error { + /// Overflow encountered. + Overflow, +} + construct_uint! { /// 128-bit unsigned integer. pub struct U128(2);