1use bedrock_vk::*;
2
3#[repr(transparent)]
4#[derive(Clone, Copy, PartialEq, Eq, Hash)]
5pub struct ResultCode(pub VkResult);
6impl core::fmt::Debug for ResultCode {
7 fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
8 write!(fmt, "[{}] {}", self.0, bedrock_vk::result_to_str(self.0))
9 }
10}
11impl core::fmt::Display for ResultCode {
12 #[inline(always)]
13 fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
14 core::fmt::Debug::fmt(self, fmt)
15 }
16}
17impl core::error::Error for ResultCode {}
18impl ResultCode {
19 #[inline]
20 pub const fn is_err(&self) -> bool {
21 self.0 < 0
22 }
23
24 #[inline]
25 pub const fn into_result(self) -> Result<Self, Self> {
26 if self.is_err() { Err(self) } else { Ok(self) }
27 }
28}
29
30#[inline(always)]
31pub const fn translate_vk_result(r: VkResult) -> Result<VkResult, ResultCode> {
32 if r < 0 { Err(ResultCode(r)) } else { Ok(r) }
33}