use std::error::Error;
use std::fmt;
use core;
pub trait VulkanObject: Sized + Send + Sync + Clone + fmt::Debug {
type NativeVulkanObject;
fn as_native_vulkan_object(&self) -> Self::NativeVulkanObject;
fn try_destroy(self) -> Result<(), TryDestroyError<Self>>;
}
pub struct TryDestroyError<T: VulkanObject> {
object: T,
kind: TryDestroyErrorKind,
}
impl<T: VulkanObject> fmt::Debug for TryDestroyError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("TryDestroyError")
.field("object", &"VulkanObject")
.field("kind", &self.kind)
.finish()
}
}
impl<T: VulkanObject> fmt::Display for TryDestroyError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.kind {
TryDestroyErrorKind::InUse(Some(strong_count)) => write!(f, "This Vulkan object still has a reference counter of {} and can not be destroyed", strong_count),
_ => write!(f, "{}", self.description()),
}
}
}
impl<T: VulkanObject> Error for TryDestroyError<T> {
fn description(&self) -> &str {
match self.kind {
TryDestroyErrorKind::Unsupported => "This Vulkan object can not be destroyed explicitly",
TryDestroyErrorKind::InUse(_) => "This Vulkan object is referenced elsewhere",
TryDestroyErrorKind::VulkanError(_) => "A Vulkan error occurred while trying to destroy the object",
}
}
}
impl<T: VulkanObject> TryDestroyError<T> {
pub fn new(object: T, kind: TryDestroyErrorKind) -> Self {
TryDestroyError {
object: object,
kind: kind,
}
}
pub fn into_vulkan_object(self) -> T {
self.object
}
pub fn kind(&self) -> TryDestroyErrorKind {
self.kind
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum TryDestroyErrorKind {
Unsupported,
InUse(Option<usize>),
VulkanError(core::Error),
}