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 Reportables 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 Reportables 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 Reportables 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 Reportables 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 + Sync + 'a>where
E: Reportable + Sync + 'a,
Makes Reportables 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 Reportables implement
Into<Box<dyn Reportable + 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 + Send + Sync + 'a>
Makes Reportables 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 Reportables implement
Into<Box<dyn Reportable + Send + Sync>> if possible,
so that they satisfy the E: Into<I> constraint used throughout this crate.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
impl Reportable for &str
impl Reportable for AddrParseError
rust-v1.77 only.impl Reportable for BorrowError
impl Reportable for BorrowMutError
impl Reportable for CharTryFromError
impl Reportable for DecodeUtf16Error
impl Reportable for Error
impl Reportable for FromBytesUntilNulError
rust-v1.69 only.impl Reportable for FromBytesWithNulError
rust-v1.64 only.impl Reportable for FromUtf8Error
impl Reportable for FromUtf16Error
impl Reportable for FromVecWithNulError
rust-v1.64 only.impl Reportable for Infallible
impl Reportable for IntoStringError
rust-v1.64 only.impl Reportable for LayoutError
impl Reportable for NulError
rust-v1.64 only.impl Reportable for ParseBoolError
impl Reportable for ParseCharError
impl Reportable for ParseFloatError
impl Reportable for ParseIntError
impl Reportable for String
impl Reportable for TryFromCharError
impl Reportable for TryFromFloatSecsError
rust-v1.66 only.