From 7c42b2132589ae3a3686ca2b25bd6b32889629f8 Mon Sep 17 00:00:00 2001 From: Valentin Kettner Date: Wed, 19 Feb 2020 16:20:18 +0100 Subject: [PATCH 1/2] Implement Error for FromDecStrErr --- uint/src/uint.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/uint/src/uint.rs b/uint/src/uint.rs index ac0ffc85e..615e880f8 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -38,6 +38,21 @@ pub enum FromDecStrErr { InvalidLength, } +impl std::fmt::Display for FromDecStrErr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + FromDecStrErr::InvalidCharacter => "a character is not in the range 0-9", + FromDecStrErr::InvalidLength => "the number is too large for the type", + } + ) + } +} + +impl std::error::Error for FromDecStrErr {} + #[macro_export] #[doc(hidden)] macro_rules! impl_map_from { From d8210552e43cf3f4b89b558d88734283f40b0a41 Mon Sep 17 00:00:00 2001 From: Valentin Kettner Date: Fri, 21 Feb 2020 14:08:19 +0100 Subject: [PATCH 2/2] Only implement Error with std feature --- uint/src/uint.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 615e880f8..493e2e21e 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -38,6 +38,7 @@ pub enum FromDecStrErr { InvalidLength, } +#[cfg(feature = "std")] impl std::fmt::Display for FromDecStrErr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( @@ -51,6 +52,7 @@ impl std::fmt::Display for FromDecStrErr { } } +#[cfg(feature = "std")] impl std::error::Error for FromDecStrErr {} #[macro_export]