Skip to content
Myr

Use Self in signatures of Error constructors

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 9e2e3c3 · Browse files · 1 file+5 added−5 removed
This commit

State

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

Diff stats

1 file+5 added−5 removed

  • other:+5 added−5 removed

1 file+5 added−5 removed

modified:src/error.rs+5 added-5 removed
26 unmodified lines
27 /// will be as well.28 ///29 /// If the error type does not provide a backtrace, a backtrace will be30 /// created here to ensure that a backtrace exists.31 pub fn new<E>(error: E) -> Error31 pub fn new<E>(error: E) -> Self32 where33 E: StdError + Send + Sync + 'static,34 {35 Error::construct(error, TypeId::of::<E>())36 }3738 #[doc(hidden)]39 pub fn new_adhoc<M>(message: M) -> Error39 pub fn new_adhoc<M>(message: M) -> Self40 where41 M: Display + Debug + Send + Sync + 'static,42 {43 Error::construct(MessageError(message), TypeId::of::<M>())44 }4546 fn construct<E>(error: E, type_id: TypeId) -> Error46 fn construct<E>(error: E, type_id: TypeId) -> Self47 where48 E: StdError + Send + Sync + 'static,49 {50 unsafe {
56 unmodified lines
107 TypeId::of::<E>() == self.inner.type_id108 }109110 /// Attempt to downcast the error object to a concrete type.111 pub fn downcast<E>(self) -> Result<E, Error>111 pub fn downcast<E>(self) -> Result<E, Self>112 where113 E: Display + Debug + Send + Sync + 'static,114 {115 if let Some(error) = self.downcast_ref::<E>() {
36 unmodified lines
152impl<E> From<E> for Error153where154 E: StdError + Send + Sync + 'static,155{156 fn from(error: E) -> Error {156 fn from(error: E) -> Self {157 Error::new(error)158 }159}160
181 unmodified lines