use std::rc::Rc;
use std::borrow::Cow;
pub type Result<T> = std::result::Result<T, EdError>;
#[macro_use]
mod internal;
pub use internal::*;
pub trait UIErrorTrait: std::error::Error + as_any::AsAny + 'static {}
#[derive(Clone, Debug)]
pub struct UIError {
pub inner: Rc<dyn UIErrorTrait>,
}
impl UIError {
pub fn downcast_ref<T: UIErrorTrait>(&self) -> Option<&T> {
use as_any::Downcast;
(&*self.inner).downcast_ref::<T>()
}
}
pub trait IOErrorTrait: std::error::Error + as_any::AsAny + 'static {}
#[derive(Clone, Debug)]
pub struct IOError {
pub inner: Rc<dyn IOErrorTrait>,
}
impl IOError {
pub fn downcast_ref<T: IOErrorTrait>(&self) -> Option<&T> {
use as_any::Downcast;
(&*self.inner).downcast_ref::<T>()
}
}
mod display;
mod partialeq;
#[derive(Debug, Clone)]
pub enum EdError {
Internal(InternalError),
IO(IOError),
UI(UIError),
InfiniteRecursion,
IndexTooBig{index: usize, buffer_len: usize},
Line0Invalid,
SelectionEmpty((usize, usize)),
SelectionForbidden,
UnsavedChanges,
NoOp,
UndoIndexNegative{relative_undo_limit: usize},
UndoIndexTooBig{index: usize, history_len: usize, relative_redo_limit: usize},
CommandEscapeForbidden(String),
TagInvalid(String),
TagNoMatch(char),
RegexInvalid{regex: String, error: regex::Error},
RegexNoMatch(String),
PrintAfterWipe,
DefaultFileUnset,
DefaultShellCommandUnset,
DefaultSArgsUnset,
IndexSpecialAfterStart{prior_index: String, special_index: char},
IndexNotInt(String),
OffsetNotInt(String),
IndicesUnrelated{prior_index: String, unrelated_index: String},
IndexUnfinished(String),
CommandUndefined(char),
ArgumentListEscapedEnd(String),
ArgumentsWrongNr{expected: Cow<'static, str>, received: usize},
ScrollNotInt(String),
UndoStepsNotInt(String),
ReflowNotInt{error: String, text: String},
MacroUndefined(String),
FlagDuplicate(char),
FlagUndefined(char),
}
impl std::error::Error for EdError {}
impl From<UIError> for EdError {
fn from(e: UIError) -> Self {
Self::UI(e)
}
}
impl<E: UIErrorTrait> From<E> for UIError {
fn from(e: E) -> Self {
Self{ inner: Rc::new(e) }
}
}
impl From<IOError> for EdError {
fn from(e: IOError) -> Self {
Self::IO(e)
}
}
impl<E: IOErrorTrait> From<E> for IOError {
fn from(e: E) -> Self {
Self{ inner: Rc::new(e) }
}
}
impl From<InternalError> for EdError {
fn from(e: InternalError) -> Self {
Self::Internal(e)
}
}
impl EdError {
pub fn regex_error<S: Into<String>>(error: regex::Error, regex: S) -> Self {
Self::RegexInvalid{regex: regex.into(), error: error}
}
}