use crate::types::VkError;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[non_exhaustive]
#[doc = crate::man_link!(VkResult)]
pub enum Error {
Other,
InvalidArgument,
InvalidState,
OutOfBounds,
SynchronizationError,
LimitExceeded,
#[doc = crate::man_link!(VkResult)]
NotReady,
#[doc = crate::man_link!(VkResult)]
Timeout,
#[doc = crate::man_link!(VkResult)]
Incomplete,
#[doc = crate::man_link!(VkResult)]
OutOfHostMemory,
#[doc = crate::man_link!(VkResult)]
OutOfDeviceMemory,
#[doc = crate::man_link!(VkResult)]
InitializationFailed,
#[doc = crate::man_link!(VkResult)]
ExtensionNotPresent,
#[doc = crate::man_link!(VkResult)]
FeatureNotPresent,
#[doc = crate::man_link!(VkResult)]
IncompatibleDriver,
#[doc = crate::man_link!(VkResult)]
DeviceLost,
#[doc = crate::man_link!(VkResult)]
SurfaceLostKHR,
#[doc = crate::man_link!(VkResult)]
OutOfPoolMemory,
#[doc = crate::man_link!(VkResult)]
SuboptimalHKR,
#[doc = crate::man_link!(VkResult)]
OutOfDateKHR,
#[doc = crate::man_link!(VkResult)]
FullScreenExclusiveModeLostEXT,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(self, f)
}
}
impl std::error::Error for Error {}
impl From<VkError> for Error {
fn from(err: VkError) -> Self {
match err.0.get() {
1 => Self::NotReady,
2 => Self::Timeout,
5 => Self::Incomplete,
-1 => Self::OutOfHostMemory,
-2 => Self::OutOfDeviceMemory,
-3 => Self::InitializationFailed,
-4 => Self::DeviceLost,
-7 => Self::ExtensionNotPresent,
-8 => Self::FeatureNotPresent,
-9 => Self::IncompatibleDriver,
-1000000000 => Self::SurfaceLostKHR,
-1000069000 => Self::OutOfPoolMemory,
1000001003 => Self::SuboptimalHKR,
-1000001004 => Self::OutOfDateKHR,
-1000255000 => Self::FullScreenExclusiveModeLostEXT,
_ => Self::Other,
}
}
}
pub type Result<T> = std::result::Result<T, Error>;
pub struct ErrorAndSelf<T>(pub Error, pub T);
impl<T> std::fmt::Debug for ErrorAndSelf<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.0, f)
}
}
impl<T> std::fmt::Display for ErrorAndSelf<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.0, f)
}
}
impl<T> From<ErrorAndSelf<T>> for Error {
fn from(ErrorAndSelf(err, _): ErrorAndSelf<T>) -> Self {
err
}
}
impl<T> std::error::Error for ErrorAndSelf<T> {}
pub type ResultAndSelf<T, S> = std::result::Result<T, ErrorAndSelf<S>>;