errors
parent
132e964f8c
commit
7334ff6bd5
|
@ -16,7 +16,7 @@ members = ["source/leela", "source/tycho"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
failure = "0.1"
|
failure = {version = "0.1", features = ["std"]}
|
||||||
serde = {version = "1.0", features = ["derive"]}
|
serde = {version = "1.0", features = ["derive"]}
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|
|
@ -32,7 +32,7 @@ macro_rules! c_enum
|
||||||
{
|
{
|
||||||
match n {
|
match n {
|
||||||
$($value => Ok($E::$Enum),)+
|
$($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(0), Ok(TestEnum::Zero));
|
||||||
assert_eq!(TestEnum::from_repr(1), Ok(TestEnum::One));
|
assert_eq!(TestEnum::from_repr(1), Ok(TestEnum::One));
|
||||||
assert_eq!(TestEnum::from_repr(2), Ok(TestEnum::Two));
|
assert_eq!(TestEnum::from_repr(2), Ok(TestEnum::Two));
|
||||||
assert_eq!(TestEnum::from_repr(3), Err(ReprError(3)));
|
assert_eq!(TestEnum::from_repr(3), Err(ReprError::new(3)));
|
||||||
assert_eq!(TestEnum::from_repr(4), Err(ReprError(4)));
|
assert_eq!(TestEnum::from_repr(4), Err(ReprError::new(4)));
|
||||||
assert_eq!(TestEnum::from_repr(5), Err(ReprError(5)));
|
assert_eq!(TestEnum::from_repr(5), Err(ReprError::new(5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -31,6 +31,12 @@ macro_rules! bail {
|
||||||
/// Returns an `Error` with a static string.
|
/// Returns an `Error` with a static string.
|
||||||
pub fn err_msg(msg: &'static str) -> Error {Error::from(ErrMsg(msg))}
|
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 ReprError {}
|
||||||
impl Fail for ErrMsg {}
|
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
|
impl fmt::Display for ErrMsg
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
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.
|
/// A representation error for an integer.
|
||||||
#[derive(PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct ReprError(pub i64);
|
pub struct ReprError(i64);
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct ErrMsg(&'static str);
|
struct ErrMsg(&'static str);
|
||||||
|
|
||||||
/// A generic `failure` based `Result` type.
|
/// A generic `failure` based `Result` type.
|
||||||
|
|
Loading…
Reference in New Issue