Trait Reportable

Source
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.

Source§

fn from(val: E) -> Self

Converts to this type from the input type.
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.

Source§

fn from(val: E) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<E> for Box<dyn Reportable + Send + Sync + 'a>
where E: 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.

Source§

fn from(val: E) -> Self

Converts to this type from the input type.
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.

Source§

fn from(val: E) -> Self

Converts to this type from the input type.

Implementations on Foreign Types§

Source§

impl Reportable for &str

Source§

impl Reportable for Infallible

Source§

impl Reportable for FromBytesWithNulError

Source§

impl Reportable for TryReserveError

Source§

impl Reportable for FromVecWithNulError

Source§

impl Reportable for IntoStringError

Source§

impl Reportable for NulError

Source§

impl Reportable for FromUtf8Error

Source§

impl Reportable for FromUtf16Error

Source§

impl Reportable for String

Source§

impl Reportable for LayoutError

Source§

impl Reportable for TryFromSliceError

Source§

impl Reportable for BorrowError

Source§

impl Reportable for BorrowMutError

Source§

impl Reportable for CharTryFromError

Source§

impl Reportable for ParseCharError

Source§

impl Reportable for DecodeUtf16Error

Source§

impl Reportable for TryFromCharError

Source§

impl Reportable for FromBytesUntilNulError

Source§

impl Reportable for Error

Source§

impl Reportable for AddrParseError

Source§

impl Reportable for ParseFloatError

Source§

impl Reportable for ParseIntError

Source§

impl Reportable for TryFromIntError

Source§

impl Reportable for ParseBoolError

Source§

impl Reportable for Utf8Error

Source§

impl Reportable for TryFromFloatSecsError

Implementors§

Source§

impl Reportable for AdHocError

Source§

impl<I> Reportable for ErrorData<I>
where I: Display + Debug,

Source§

impl<I> Reportable for lazy_errors::Error<I>
where I: Display + Debug,

Source§

impl<I> Reportable for StashedErrors<I>
where I: Display + Debug,

Source§

impl<I> Reportable for WrappedError<I>
where I: Display + Debug,