#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum FailureClass {
OutOfMemory,
AllocationFailed,
DeviceLost,
DeviceHung,
ReadbackFailed,
GpuTimeout,
ValidationFailed,
InvalidInput,
HostExited,
OutputIoFailed,
StorageQuotaExceeded,
ResourceLimit,
ResourceBusy,
Cancelled,
Defect,
Unknown,
}
impl FailureClass {
pub const ALL: [Self; 16] = [
Self::OutOfMemory,
Self::AllocationFailed,
Self::DeviceLost,
Self::DeviceHung,
Self::ReadbackFailed,
Self::GpuTimeout,
Self::ValidationFailed,
Self::InvalidInput,
Self::HostExited,
Self::OutputIoFailed,
Self::StorageQuotaExceeded,
Self::ResourceLimit,
Self::ResourceBusy,
Self::Cancelled,
Self::Defect,
Self::Unknown,
];
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::OutOfMemory => "OUT_OF_MEMORY",
Self::AllocationFailed => "ALLOCATION_FAILED",
Self::DeviceLost => "DEVICE_LOST",
Self::DeviceHung => "DEVICE_HUNG",
Self::ReadbackFailed => "READBACK_FAILED",
Self::GpuTimeout => "GPU_TIMEOUT",
Self::ValidationFailed => "VALIDATION_FAILED",
Self::InvalidInput => "INVALID_INPUT",
Self::HostExited => "HOST_EXITED",
Self::OutputIoFailed => "OUTPUT_IO_FAILED",
Self::StorageQuotaExceeded => "STORAGE_QUOTA_EXCEEDED",
Self::ResourceLimit => "RESOURCE_LIMIT",
Self::ResourceBusy => "RESOURCE_BUSY",
Self::Cancelled => "CANCELLED",
Self::Defect => "DEFECT",
Self::Unknown => "UNKNOWN",
}
}
#[must_use]
pub fn parse(code: &str) -> Option<Self> {
Self::ALL.into_iter().find(|class| class.as_str() == code)
}
}
impl std::fmt::Display for FailureClass {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.as_str())
}
}