#[cfg(doctest)]
#[doc = include_str!("../README.md")]
pub struct ReadMeDocTests;
pub mod macros;
pub mod traceable;
use std::fmt::{Debug, Display};
use thiserror::*;
#[derive(Error, Debug, Clone, PartialEq)]
#[error("{} ({})",.s,.e)]
pub struct SWrap<E: Debug + Display> {
e: E,
s: &'static str,
}
#[derive(Error, Debug, Clone, PartialEq)]
#[error("{} ({})",.s,.e)]
pub struct SgWrap<E: Debug + Display> {
e: E,
s: String,
}
#[derive(Error, Debug, Clone, PartialEq)]
#[error("{}",.0)]
pub struct SError(pub &'static str);
#[derive(Error, Debug, Clone, PartialEq)]
#[error("{}",.0)]
pub struct SgError(pub String);
pub fn e_str<T>(s: &'static str) -> anyhow::Result<T> {
Err(SError(s).into())
}
pub fn e_string<T>(s: String) -> anyhow::Result<T> {
Err(SgError(s).into())
}
pub trait OpError: Sized {
type V;
fn e_str(self, s: &'static str) -> anyhow::Result<Self::V>;
fn e_string(self, s: String) -> anyhow::Result<Self::V>;
}
impl<V> OpError for Option<V> {
type V = V;
fn e_str(self, s: &'static str) -> anyhow::Result<Self::V> {
self.ok_or(SError(s).into())
}
fn e_string(self, s: String) -> anyhow::Result<Self::V> {
self.ok_or(SgError(s).into())
}
}
pub trait ResError: Sized {
type V;
type E: Debug + Display + Send + Sync + 'static;
fn e_str(self, s: &'static str) -> anyhow::Result<Self::V>;
fn e_string(self, s: String) -> anyhow::Result<Self::V>;
}
impl<T, E: Debug + Display + Sync + Send + 'static> ResError for Result<T, E> {
type V = T;
type E = E;
fn e_str(self, s: &'static str) -> anyhow::Result<Self::V> {
self.map_err(|e| SWrap { s, e }.into())
}
fn e_string(self, s: String) -> anyhow::Result<Self::V> {
self.map_err(|e| SgWrap { s, e }.into())
}
}