aquaengine 0.0.2

AquaEngine is a RAD framework for graphics and computes
Documentation
//! Errors

use std::fmt;
use std::ffi::NulError;
use std::error::Error;

#[derive(Debug)]
/// Errors on a `AquaEngine` application
pub enum Application{
    /// Errors on a `Engine`
    Engine(Engine),

    /// Nul pointer from FFI
    Nul(NulError),
}

impl Error for Application{
    fn description(&self) -> &str {
        match *self {
            Application::Engine(ref e) => e.description(),
            Application::Nul(ref e) => e.description(),
        }
    }

    fn cause(&self) -> Option<&Error> {
        match *self {
            Application::Engine(ref e) => Some(e),
            Application::Nul(ref e) => Some(e),
        }
    }
}

impl fmt::Display for Application {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Application::Engine(ref e) => e.fmt(f),
            Application::Nul(ref e) => e.fmt(f),
        }
    }
}

impl From<Engine> for Application {
    fn from(err: Engine) -> Self {
        Application::Engine(err)
    }
}

impl From<NulError> for Application{
    fn from(err: NulError) -> Self {
        Application::Nul(err)
    }
}

#[derive(Debug, Clone, Copy)]
/// Errors on a `Engine`
pub enum Engine {
    /// Version malformed
    ///
    /// Used by Engine::version
    InvalidVersion,
}

impl Error for Engine {
    fn description(&self) -> &str {
        match *self {
            Engine::InvalidVersion => "Invalid version",
        }
    }
}

impl fmt::Display for Engine {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Engine::InvalidVersion => write!(f, "The version is invalid"),
        }
    }
}

#[derive(Debug)]
/// Errors on a `Instance`
pub enum Instance {
    /// Errors on a `Application`
    Application(Application),
}

impl Error for Instance {
    fn description(&self) -> &str {
        match *self {
            Instance::Application(ref e) => e.description(),
        }
    }

    fn cause(&self) -> Option<&Error> {
        match *self {
            Instance::Application(ref e) => Some(e),
        }
    }
}

impl fmt::Display for Instance {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Instance::Application(ref e) => e.fmt(f),
        }
    }
}

impl From<Application> for Instance {
    fn from(err: Application) -> Self {
        Instance::Application(err)
    }
}