Maraiah/src/durandal/err.rs

31 lines
766 B
Rust

//! Error handling.
pub use failure::{Error, Fail, format_err};
use crate::durandal::traits::PrimInt;
use std::fmt;
#[derive(PartialEq)]
pub struct ReprError<T>(pub T) where T: PrimInt;
impl<T> Fail for ReprError<T> where T: PrimInt {}
impl<T> fmt::Display for ReprError<T> where T: PrimInt
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{write!(f, "representation error (got {})", self.0)}
}
impl<T> fmt::Debug for ReprError<T> where T: PrimInt
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{fmt::Display::fmt(self, f)}
}
pub type ResultS<T> = Result<T, Error>;
pub fn err_msg<T>(s: &'static str) -> ResultS<T> {Err(failure::err_msg(s))}
pub fn err_msg_v (s: &'static str) -> Error { failure::err_msg(s) }
// EOF