Skip to main content

Reportable

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

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Reportable for &str

Source§

impl Reportable for AddrParseError

Available on crate feature rust-v1.77 only.
Source§

impl Reportable for BorrowError

Source§

impl Reportable for BorrowMutError

Source§

impl Reportable for CharTryFromError

Source§

impl Reportable for DecodeUtf16Error

Source§

impl Reportable for Error

Source§

impl Reportable for FromBytesUntilNulError

Available on crate feature rust-v1.69 only.
Source§

impl Reportable for FromBytesWithNulError

Available on crate feature rust-v1.64 only.
Source§

impl Reportable for FromUtf8Error

Source§

impl Reportable for FromUtf16Error

Source§

impl Reportable for FromVecWithNulError

Available on crate feature rust-v1.64 only.
Source§

impl Reportable for Infallible

Source§

impl Reportable for IntoStringError

Available on crate feature rust-v1.64 only.
Source§

impl Reportable for LayoutError

Source§

impl Reportable for NulError

Available on crate feature rust-v1.64 only.
Source§

impl Reportable for ParseBoolError

Source§

impl Reportable for ParseCharError

Source§

impl Reportable for ParseFloatError

Source§

impl Reportable for ParseIntError

Source§

impl Reportable for String

Source§

impl Reportable for TryFromCharError

Source§

impl Reportable for TryFromFloatSecsError

Available on crate feature rust-v1.66 only.
Source§

impl Reportable for TryFromIntError

Source§

impl Reportable for TryFromSliceError

Source§

impl Reportable for TryReserveError

Source§

impl Reportable for Utf8Error

Implementors§

Source§

impl Reportable for AdHocError

Source§

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

Source§

impl<I> Reportable for ErrorData<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,