use crate::functions::{ApiError, ApiWrapperError, ProgramBuildError, VersionLowError};
use crate::util::UtilError;
use crate::{EmptyInfoResultError, Status};
pub type Result<T> = ::std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
String(String),
#[error("{0}")]
FfiNul(#[from] ::std::ffi::NulError),
#[error("{0}")]
Io(#[from] ::std::io::Error),
#[error("{0}")]
FromUtf8(#[from] ::std::string::FromUtf8Error),
#[error("{0}")]
IntoString(#[from] ::std::ffi::IntoStringError),
#[error("{0}")]
EmptyInfoResult(EmptyInfoResultError),
#[error("{0}")]
Util(UtilError),
#[error("{0}")]
Api(ApiError),
#[error("{0}")]
VersionLow(VersionLowError),
#[error("{0}")]
ProgramBuild(ProgramBuildError),
#[error("{0}")]
ApiWrapper(ApiWrapperError),
}
impl Error {
pub fn api_status(&self) -> Option<Status> {
match *self {
Error::Api(ref err) => Some(err.status()),
_ => None,
}
}
}
impl<'a> From<&'a str> for Error {
fn from(desc: &'a str) -> Self {
Error::String(String::from(desc))
}
}
impl From<String> for Error {
fn from(desc: String) -> Self {
Error::String(desc)
}
}
impl From<UtilError> for Error {
fn from(err: UtilError) -> Self {
Error::Util(err)
}
}
impl From<ApiError> for Error {
fn from(err: ApiError) -> Self {
Error::Api(err)
}
}
impl From<VersionLowError> for Error {
fn from(err: VersionLowError) -> Self {
Error::VersionLow(err)
}
}
impl From<ProgramBuildError> for Error {
fn from(err: ProgramBuildError) -> Self {
Error::ProgramBuild(err)
}
}
impl From<ApiWrapperError> for Error {
fn from(err: ApiWrapperError) -> Self {
Error::ApiWrapper(err)
}
}