From 4147aa5450383d1dba9bc3739d56408fed8b0b58 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Sun, 23 Oct 2022 09:52:19 -0400 Subject: Implement From --- src/exun.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/exun.rs') diff --git a/src/exun.rs b/src/exun.rs index 8a20be6..b870471 100644 --- a/src/exun.rs +++ b/src/exun.rs @@ -3,6 +3,9 @@ use core::fmt::{self, Debug, Display}; #[cfg(feature = "std")] use std::error::Error; +#[cfg(feature = "alloc")] +use crate::UnexpectedError; + pub use Exun::{Expected, Unexpected}; /// `Expect` is a type that represents either the expected error type @@ -36,12 +39,20 @@ impl Error for Exun { } } -impl From for Exun { +#[cfg(feature = "std")] +impl From for Exun { fn from(e: E) -> Self { Expected(e) } } +#[cfg(feature = "alloc")] +impl From for Exun { + fn from(ue: UnexpectedError) -> Self { + Unexpected(ue) + } +} + impl Exun { /// Converts from `Expect` to [`Option`]. /// -- cgit v1.2.3