1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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),
}