use std::{error, fmt};
#[derive(Clone)]
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",
}
}
}
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))
}
}