vltk 0.1.2

A simplified toolkit for creating applications using Vulkan
Documentation
use std::{error, fmt};

#[derive(Clone)]
/// Error kind of VlTkError
pub enum ErrorKind {
    VkInitialize,
    VkInstanceInitializeError,
}

impl ErrorKind {
    pub fn description(&self) -> &'static str {
        match self {
            ErrorKind::VkInitialize => "Vulkan initialization failed",
            ErrorKind::VkInstanceInitializeError => "Vulkan instance initialization failed",
        }
    }
}

// Errors
/// VlTk errors
pub struct VlTkError {
    _error: _VlTkError,
}

impl VlTkError {
    pub(crate) fn new<E>(kind: ErrorKind, error: E) -> Self
    where
        E: Into<Box<dyn error::Error + Send + Sync>>,
    {
        VlTkError {
            _error: _VlTkError::Custom((kind, error.into())),
        }
    }
}

enum _VlTkError {
    Simple(ErrorKind),
    Custom((ErrorKind, Box<dyn error::Error + Send + Sync>)),
}

impl fmt::Display for VlTkError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match &self._error {
            _VlTkError::Simple(s) => f.write_str(s.description()),
            _VlTkError::Custom(c) => f.write_str(c.0.description()),
        }
    }
}

impl fmt::Debug for VlTkError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_fmt(format_args!("{}", self))
    }
}