use core::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
BackendUnavailable(&'static str),
Unsupported(&'static str),
OutOfMemory,
LaunchFailure { code: i32 },
InvalidArgument(&'static str),
Backend {
backend: crate::BackendKind,
code: i64,
},
Other(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::BackendUnavailable(b) => write!(f, "backend `{b}` unavailable"),
Error::Unsupported(s) => write!(f, "unsupported: {s}"),
Error::OutOfMemory => f.write_str("out of memory"),
Error::LaunchFailure { code } => write!(f, "kernel launch failed (code {code})"),
Error::InvalidArgument(s) => write!(f, "invalid argument: {s}"),
Error::Backend { backend, code } => write!(f, "{backend:?} error {code}"),
Error::Other(s) => f.write_str(s),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub type Result<T, E = Error> = core::result::Result<T, E>;