Skip to content
Myr

Introduce safe from_std and matching from_adhoc

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 2a9e5b6 · Browse files · 2 files+10 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−3 removed

  • other:+10 added−3 removed

2 files+10 added−3 removed

modified:src/error.rs+9 added-2 removed
31 unmodified lines
32 pub fn new<E>(error: E) -> Self33 where34 E: StdError + Send + Sync + 'static,35 {36 let type_id = TypeId::of::<E>();36 let backtrace = backtrace_if_absent!(error);37 Error::from_std(error, backtrace)38 }3940 pub(crate) fn from_std<E>(error: E, backtrace: Option<Backtrace>) -> Self41 where42 E: StdError + Send + Sync + 'static,43 {44 let type_id = TypeId::of::<E>();4546 // Safety: passing typeid of the right type E.47 unsafe { Error::construct(error, type_id, backtrace) }48 }4943 pub(crate) fn new_adhoc<M>(message: M, backtrace: Option<Backtrace>) -> Self50 pub(crate) fn from_adhoc<M>(message: M, backtrace: Option<Backtrace>) -> Self51 where52 M: Display + Debug + Send + Sync + 'static,53 {54 let error = MessageError(message);
465 unmodified lines
modified:src/lib.rs+1 added-1 removed
406 unmodified lines
407 pub fn new_adhoc<M>(message: M) -> Error408 where409 M: Display + Debug + Send + Sync + 'static,410 {411 Error::new_adhoc(message, backtrace!())411 Error::from_adhoc(message, backtrace!())412 }413}