From 0790c84b59907ee5fe2dfc5a4d51d593098a281c Mon Sep 17 00:00:00 2001 From: Botahamec Date: Sat, 22 Oct 2022 22:04:21 -0400 Subject: From impls and Send+Sync --- src/unexpected.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/unexpected.rs b/src/unexpected.rs index 6e5548b..496c6c9 100644 --- a/src/unexpected.rs +++ b/src/unexpected.rs @@ -6,15 +6,15 @@ use alloc::boxed::Box; #[cfg(feature = "std")] use std::error::Error; -pub trait Errorable: Display + Debug {} -impl Errorable for T {} +pub trait Errorable: Display + Debug + Send + Sync {} +impl Errorable for T {} #[derive(Debug)] #[non_exhaustive] enum ErrorTy { Message(Box), #[cfg(feature = "std")] - Error(Box), + Error(Box), } #[derive(Debug)] @@ -43,10 +43,23 @@ impl Error for UnexpectedError { } } +impl From<&str> for UnexpectedError { + fn from(s: &str) -> Self { + String::from(s).into() + } +} + +impl From for UnexpectedError { + fn from(s: String) -> Self { + Self::msg(s) + } +} + impl UnexpectedError { /// Create a new `UnexpectedError` from any [`Error`] type. /// - /// The error must be `'static` so that the `UnexpectedError` will be too. + /// The error must be thread-safe and `'static` so that the + /// `UnexpectedError` will be too. /// /// # Examples /// @@ -58,7 +71,7 @@ impl UnexpectedError { /// let err = UnexpectedError::new(core::fmt::Error); /// ``` #[cfg(feature = "std")] - pub fn new(e: E) -> Self { + pub fn new(e: E) -> Self { Self { internal: ErrorTy::Error(Box::new(e)), } -- cgit v1.2.3