From 665423f99248fb6a8b29da7a5250c2d5e52230da Mon Sep 17 00:00:00 2001 From: Nathan West Date: Sat, 7 Nov 2020 00:50:55 -0500 Subject: [PATCH] Add trait implementations to ParseQuantityError. --- src/lib.rs | 17 +++++++++++++++++ src/tests/asserts.rs | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ec45d22f..efc91d4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -621,6 +621,8 @@ pub mod fmt { /// Unicode string slice manipulation for quantities. pub mod str { + use crate::lib::fmt::{self, Display, Formatter}; + /// Represents an error encountered while parsing a string into a `Quantity`. #[allow(missing_copy_implementations)] #[derive(Clone, Debug, Eq, PartialEq)] @@ -641,4 +643,19 @@ pub mod str { /// unit name (description) is correct. UnknownUnit, } + + impl Display for ParseQuantityError { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + use ParseQuantityError::*; + + match *self { + NoSeparator => write!(f, "no space between quantity and units"), + ValueParseError => write!(f, "error parsing unit quantity"), + UnknownUnit => write!(f, "unrecognized unit of measure"), + } + } + } + + #[cfg(feature = "std")] + impl crate::lib::error::Error for ParseQuantityError {} } diff --git a/src/tests/asserts.rs b/src/tests/asserts.rs index 09535932..a2b3795e 100644 --- a/src/tests/asserts.rs +++ b/src/tests/asserts.rs @@ -17,6 +17,12 @@ assert_impl_all!(DisplayStyle: assert_not_impl_any!(DisplayStyle: Binary, Display, Eq, Hash, LowerExp, LowerHex, Ord, Octal, PartialEq, PartialOrd, UpperExp, UpperHex); +#[rustfmt::skip] +assert_impl_all!(ParseQuantityError: + Clone, Debug, Display, Eq, PartialEq, Send, Sync, Unpin); +#[rustfmt::skip] +assert_not_impl_any!(ParseQuantityError: + Binary, Copy, Hash, LowerExp, LowerHex, Ord, Octal, PartialOrd, UpperExp, UpperHex); storage_types! { types: Float;