use std::error::Error;
use std::fmt::Debug;
#[derive(Debug)]
pub struct RuntimeError(pub Box<dyn Debug + Send>);
impl RuntimeError {
#[inline]
pub fn expect<T>(message: &'static str) -> Result<T, Self> {
Err(Self(Box::new(message)))
}
#[inline]
pub fn expect_os<T>(message: std::ffi::OsString) -> Result<T, Self> {
Err(Self(Box::new(message)))
}
#[inline]
pub fn message<T>(message: String) -> Result<T, Self> {
Err(Self(Box::new(message)))
}
#[inline]
pub fn unexpected<T>() -> Result<T, Self> {
Self::expect("Unexpected error")
}
#[inline]
pub fn unreachable<T>() -> Result<T, Self> {
Self::expect("Unreachable code")
}
#[inline]
pub fn unimplemented<T>() -> Result<T, Self> {
Self::expect("Unimplemented yet")
}
}
impl<E> From<E> for RuntimeError
where
E: Error + Send + 'static,
{
#[inline]
fn from(error: E) -> Self {
Self(Box::new(error))
}
}