use std::{io::Error as IoError, result};
use crate::sys::NcError;
pub type NotcursesResult<T> = result::Result<T, NotcursesError>;
#[derive(Debug)]
#[non_exhaustive]
pub enum NotcursesError {
NcError(NcError),
IoError(IoError),
Message(String),
}
impl NotcursesError {
pub fn msg<T>(string: &str) -> NotcursesResult<T> {
Err(Self::Message(string.into()))
}
}
mod core_impls {
use super::{NcError, NotcursesError};
use core::fmt;
impl fmt::Display for NotcursesError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
NotcursesError::NcError(e) => e.fmt(f),
NotcursesError::IoError(e) => e.fmt(f),
NotcursesError::Message(string) => write!(f, "Message: {}", string),
}
}
}
impl From<NcError> for NotcursesError {
fn from(e: NcError) -> Self {
Self::NcError(e)
}
}
}
mod std_impls {
use super::NotcursesError;
impl std::error::Error for NotcursesError {}
}