Skip to content

Commit

Permalink
Merge pull request #217 from Lucretiel:error-traits
Browse files Browse the repository at this point in the history
Add trait implementations to ParseQuantityError.
  • Loading branch information
iliekturtles committed Nov 25, 2020
2 parents d0c4d86 + 665423f commit bc1bb9a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {}
}
6 changes: 6 additions & 0 deletions src/tests/asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bc1bb9a

Please sign in to comment.