use std::ffi::NulError;
use std::io::Error as IoError;
use std::num::TryFromIntError;
use std::str::Utf8Error;
#[cfg(any(target_os = "android", target_os = "linux"))]
use nix::Error as NixError;
use remain::sorted;
use thiserror::Error;
#[cfg(target_os = "windows")]
use winapi::shared::ntdef::NTSTATUS;
#[sorted]
#[derive(Error, Debug)]
pub enum MesaError {
#[error("invalid Mesa handle")]
InvalidMesaHandle,
#[error("an input/output error occur: {0}")]
IoError(IoError),
#[cfg(any(target_os = "android", target_os = "linux"))]
#[error("The errno is {0}")]
NixError(NixError),
#[cfg(target_os = "windows")]
#[error("Failed with NTSTATUS 0x{0:x}")]
NtStatus(NTSTATUS),
#[error("Nul Error occured {0}")]
NulError(NulError),
#[error("int conversion failed: {0}")]
TryFromIntError(TryFromIntError),
#[error("the requested function is not implemented")]
Unsupported,
#[error("an utf8 error occured: {0}")]
Utf8Error(Utf8Error),
#[error("violation of the rutabaga spec: {0}")]
WithContext(&'static str),
}
#[cfg(any(target_os = "android", target_os = "linux"))]
impl From<NixError> for MesaError {
fn from(e: NixError) -> MesaError {
MesaError::NixError(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>;