use std::ffi::NulError;
use std::io::Error as IoError;
use std::num::TryFromIntError;
use std::str::Utf8Error;
use remain::sorted;
#[cfg(any(target_os = "android", target_os = "linux"))]
use rustix::io::Errno as RustixError;
use thiserror::Error;
#[sorted]
#[derive(Error, Debug)]
pub enum MesaError {
#[error("invalid Mesa handle")]
InvalidMesaHandle,
#[error("an input/output error occur: {0}")]
IoError(IoError),
#[error("Nul Error occured {0}")]
NulError(NulError),
#[cfg(any(target_os = "android", target_os = "linux"))]
#[error("The errno is {0}")]
RustixError(RustixError),
#[error("int conversion failed: {0}")]
TryFromIntError(TryFromIntError),
#[error("the requested function is not implemented")]
Unsupported,
#[error("an utf8 error occured: {0}")]
Utf8Error(Utf8Error),
#[error("operation failed: {0}")]
WithContext(&'static str),
}
#[cfg(any(target_os = "android", target_os = "linux"))]
impl From<RustixError> for MesaError {
fn from(e: RustixError) -> MesaError {
MesaError::RustixError(e)
}
}
impl From<NulError> for MesaError {
fn from(e: NulError) -> MesaError {
MesaError::NulError(e)
}
}
impl From<IoError> for MesaError {
fn from(e: IoError) -> MesaError {
MesaError::IoError(e)
}
}
impl From<TryFromIntError> for MesaError {
fn from(e: TryFromIntError) -> MesaError {
MesaError::TryFromIntError(e)
}
}
impl From<Utf8Error> for MesaError {
fn from(e: Utf8Error) -> MesaError {
MesaError::Utf8Error(e)
}
}
pub type MesaResult<T> = std::result::Result<T, MesaError>;