pub trait Reportable: Display + Debug { }
Expand description
Marker trait for types that can be put into ErrorStash
and other containers of this crate
when both std
and core::error::Error
are not available.
By default, this trait is referenced in exactly one place: Stashable
.
By implementing this trait for your custom type, you will be able to
put that type into ErrorStash
or other containers
(that use the boxed type aliases from the prelude
),
without having to specify some static type parameters.
use core::fmt::{Display, Formatter, Result};
use lazy_errors::surrogate_error_trait::{prelude::*, Reportable};
#[derive(Debug)]
struct MyType;
impl Display for MyType {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "MyType")
}
}
impl Reportable for MyType {}
let mut errs = ErrorStash::new(|| "Error summary");
errs.push(MyType);
If you need a more complex conversion, you could instead implement
From<MyType>
for Box<dyn Reportable ...>
or for Stashable
.
As long as MyType
itself does not implement Reportable
(there would be a conflicting implementation in that case),
implementing From
will make lazy_errors
convert your type
as expected when put into an ErrorStash
.
use core::fmt::{Display, Formatter, Result};
use lazy_errors::surrogate_error_trait::{prelude::*, Reportable};
struct MyExpensiveType;
impl From<MyExpensiveType> for Stashable {
fn from(val: MyExpensiveType) -> Stashable {
Box::new(String::from("Summary of data in MyType"))
// Drop MyExpensiveType now, e.g. to free memory
}
}
let mut errs = ErrorStash::new(|| "Error summary");
errs.push(MyExpensiveType);
Trait Implementations§
Source§impl<'a, E> From<E> for Box<dyn Reportable + 'a>where
E: Reportable + 'a,
Makes all Reportable
s implement
Into<Box<dyn Reportable>>
,
so that they satisfy the E: Into<I>
constraint used throughout this crate.
impl<'a, E> From<E> for Box<dyn Reportable + 'a>where
E: Reportable + 'a,
Makes all Reportable
s implement
Into<Box<dyn Reportable>>
,
so that they satisfy the E: Into<I>
constraint used throughout this crate.
Source§impl<'a, E> From<E> for Box<dyn Reportable + Send + 'a>where
E: Reportable + Send + 'a,
Makes Reportable
s implement
Into<Box<dyn Reportable + Send>>
if possible,
so that they satisfy the E: Into<I>
constraint used throughout this crate.
impl<'a, E> From<E> for Box<dyn Reportable + Send + 'a>where
E: Reportable + Send + 'a,
Makes Reportable
s implement
Into<Box<dyn Reportable + Send>>
if possible,
so that they satisfy the E: Into<I>
constraint used throughout this crate.
Source§impl<'a, E> From<E> for Box<dyn Reportable + Send + Sync + 'a>
Makes Reportable
s implement
Into<Box<dyn Reportable + Send + Sync>>
if possible,
so that they satisfy the E: Into<I>
constraint used throughout this crate.
impl<'a, E> From<E> for Box<dyn Reportable + Send + Sync + 'a>
Makes Reportable
s implement
Into<Box<dyn Reportable + Send + Sync>>
if possible,
so that they satisfy the E: Into<I>
constraint used throughout this crate.
Source§impl<'a, E> From<E> for Box<dyn Reportable + Sync + 'a>where
E: Reportable + Sync + 'a,
Makes Reportable
s implement
Into<Box<dyn Reportable + Sync>>
if possible,
so that they satisfy the E: Into<I>
constraint used throughout this crate.
impl<'a, E> From<E> for Box<dyn Reportable + Sync + 'a>where
E: Reportable + Sync + 'a,
Makes Reportable
s implement
Into<Box<dyn Reportable + Sync>>
if possible,
so that they satisfy the E: Into<I>
constraint used throughout this crate.