Skip to content
Myr

Move ContextError to error.rs in preparation for refactor

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 9f38495 · Browse files · 2 files+15 added−10 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+15 added−10 removed

  • other:+15 added−10 removed

2 files+15 added−10 removed

modified:src/context.rs+2 added-9 removed
1use crate::error::ContextError;2use crate::{Context, Error};3use std::convert::Infallible;4use std::error::Error as StdError;5use std::fmt::{self, Debug, Display};
17 unmodified lines
23 fn ext_context<C>(self, context: C) -> Error24 where25 C: Display + Send + Sync + 'static,26 {26 Error::new(ContextError {27 context,28 error: self,29 })27 Error::from_context(context, self)28 }29 }3031 impl StdError for Error {
62 unmodified lines
94 self.ok_or_else(|| Error::from_display(context(), backtrace!()))95 }96}97100pub(crate) struct ContextError<C, E> {101 pub context: C,102 pub error: E,103}10498impl<C, E> Debug for ContextError<C, E>99where100 C: Display,101 E: Debug,
52 unmodified lines
modified:src/error.rs+13 added-1 removed
1use crate::backtrace::Backtrace;2use crate::context::ContextError;2use crate::{Chain, Error};3use std::any::TypeId;4use std::error::Error as StdError;5use std::fmt::{self, Debug, Display};
50 unmodified lines
56 // same layout as the typeid specifies.57 unsafe { Error::construct(error, type_id, backtrace) }58 }5960 pub(crate) fn from_context<C, E>(context: C, error: E) -> Self61 where62 C: Display + Send + Sync + 'static,63 E: StdError + Send + Sync + 'static,64 {65 Error::new(ContextError { context, error })66 }6768 // Takes backtrace as argument rather than capturing it here so that the69 // user sees one fewer layer of wrapping noise in the backtrace.70 //71 // Unsafe because the type represented by type_id must have the same layout
334 unmodified lines
406 // NOTE: Don't use directly. Use only through vtable. Erased type may have different alignment.407 _error: E,408}409410pub(crate) struct ContextError<C, E> {411 pub context: C,412 pub error: E,413}414415#[repr(transparent)]416struct MessageError<M>(M);417418impl<M> Debug for MessageError<M>
170 unmodified lines