gdritter repos httputils / master src / error.rs
master

Tree @master (Download .tar.gz)

error.rs @masterraw · history · blame

extern crate hyper;
extern crate std;

/// An `AloysError` is one of the errors that can occur in
/// the course of running an Aloys server. This might be
/// an `IOError` from the stdlib, a `HyperError` from
/// the hyper library, or an `AloysError` from us.
#[derive(Debug)]
pub enum AloysError {
    IOError(std::io::Error),
    HyperError(hyper::error::Error),
    AloysError(String),
}

/// Convenience function for constructing an `AloysError`.
pub fn aloys_error<A>(s: String) -> Result<A, AloysError> {
    Err(AloysError::AloysError(s))
}

impl From<std::io::Error> for AloysError {
    fn from(e: std::io::Error) -> AloysError {
        AloysError::IOError(e)
    }
}

impl From<hyper::error::Error> for AloysError {
    fn from(e: hyper::error::Error) -> AloysError {
        AloysError::HyperError(e)
    }
}