png-branch
an 2019-03-04 08:59:43 -05:00
parent 132e964f8c
commit 7334ff6bd5
3 changed files with 14 additions and 23 deletions

View File

@ -16,7 +16,7 @@ members = ["source/leela", "source/tycho"]
[dependencies]
bitflags = "1.0"
failure = "0.1"
failure = {version = "0.1", features = ["std"]}
serde = {version = "1.0", features = ["derive"]}
[profile.dev]

View File

@ -32,7 +32,7 @@ macro_rules! c_enum
{
match n {
$($value => Ok($E::$Enum),)+
n => Err(ReprError(n.into()))
n => Err(ReprError::new(n))
}
}
}
@ -60,9 +60,9 @@ mod test
assert_eq!(TestEnum::from_repr(0), Ok(TestEnum::Zero));
assert_eq!(TestEnum::from_repr(1), Ok(TestEnum::One));
assert_eq!(TestEnum::from_repr(2), Ok(TestEnum::Two));
assert_eq!(TestEnum::from_repr(3), Err(ReprError(3)));
assert_eq!(TestEnum::from_repr(4), Err(ReprError(4)));
assert_eq!(TestEnum::from_repr(5), Err(ReprError(5)));
assert_eq!(TestEnum::from_repr(3), Err(ReprError::new(3)));
assert_eq!(TestEnum::from_repr(4), Err(ReprError::new(4)));
assert_eq!(TestEnum::from_repr(5), Err(ReprError::new(5)));
}
#[test]

View File

@ -31,6 +31,12 @@ macro_rules! bail {
/// Returns an `Error` with a static string.
pub fn err_msg(msg: &'static str) -> Error {Error::from(ErrMsg(msg))}
impl ReprError
{
#[inline]
pub fn new<T>(n: T) -> Self where T: Into<i64> {Self(n.into())}
}
impl Fail for ReprError {}
impl Fail for ErrMsg {}
@ -42,14 +48,6 @@ impl fmt::Display for ReprError
}
}
impl fmt::Debug for ReprError
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for ErrMsg
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
@ -58,18 +56,11 @@ impl fmt::Display for ErrMsg
}
}
impl fmt::Debug for ErrMsg
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
fmt::Display::fmt(self, f)
}
}
/// A representation error for an integer.
#[derive(PartialEq)]
pub struct ReprError(pub i64);
#[derive(Debug, PartialEq)]
pub struct ReprError(i64);
#[derive(Debug)]
struct ErrMsg(&'static str);
/// A generic `failure` based `Result` type.