Skip to content
Myr

Expand ContextError vtable to prepare for extending downcast support

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 b261a64 · Browse files · 2 files+16 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+16 added−3 removed

  • other:+16 added−3 removed

2 files+16 added−3 removed

modified:src/context.rs+2 added-1 removed
22 unmodified lines
23 fn ext_context<C>(self, context: C) -> Error24 where25 C: Display + Send + Sync + 'static,26 {27 let backtrace = backtrace_if_absent!(self);27 Error::from_context(context, self)28 Error::from_context(context, self, backtrace)29 }30 }3132 impl StdError for Error {
122 unmodified lines
modified:src/error.rs+14 added-2 removed
76 unmodified lines
77 // vtable to allow casting the DisplayError<M> to M.78 unsafe { Error::construct(error, vtable, backtrace) }79 }8081 pub(crate) fn from_context<C, E>(context: C, error: E) -> Self81 pub(crate) fn from_context<C, E>(context: C, error: E, backtrace: Option<Backtrace>) -> Self82 where83 C: Display + Send + Sync + 'static,84 E: StdError + Send + Sync + 'static,85 {86 Error::new(ContextError { context, error })86 let error: ContextError<C, E> = ContextError { context, error };8788 let vtable = &ErrorVTable {89 object_drop: object_drop::<ContextError<C, E>>,90 object_drop_front: object_drop_front::<ContextError<C, E>>,91 object_ref: object_ref::<ContextError<C, E>>,92 object_mut: object_mut::<ContextError<C, E>>,93 object_boxed: object_boxed::<ContextError<C, E>>,94 object_is: object_is::<ContextError<C, E>>,95 };9697 // Safety: passing vtable that operates on the right type.98 unsafe { Error::construct(error, vtable, backtrace) }99 }100101 // Takes backtrace as argument rather than capturing it here so that the102 // user sees one fewer layer of wrapping noise in the backtrace.
538 unmodified lines