diff options
Diffstat (limited to '')
-rw-r--r-- | vendor/thiserror/src/aserror.rs | 9 | ||||
-rw-r--r-- | vendor/thiserror/src/lib.rs | 39 | ||||
-rw-r--r-- | vendor/thiserror/src/provide.rs | 15 |
3 files changed, 59 insertions, 4 deletions
diff --git a/vendor/thiserror/src/aserror.rs b/vendor/thiserror/src/aserror.rs index c036b7b09..5fea84ef8 100644 --- a/vendor/thiserror/src/aserror.rs +++ b/vendor/thiserror/src/aserror.rs @@ -1,7 +1,7 @@ use std::error::Error; use std::panic::UnwindSafe; -pub trait AsDynError<'a> { +pub trait AsDynError<'a>: Sealed { fn as_dyn_error(&self) -> &(dyn Error + 'a); } @@ -39,3 +39,10 @@ impl<'a> AsDynError<'a> for dyn Error + Send + Sync + UnwindSafe + 'a { self } } + +pub trait Sealed {} +impl<'a, T: Error + 'a> Sealed for T {} +impl<'a> Sealed for dyn Error + 'a {} +impl<'a> Sealed for dyn Error + Send + 'a {} +impl<'a> Sealed for dyn Error + Send + Sync + 'a {} +impl<'a> Sealed for dyn Error + Send + Sync + UnwindSafe + 'a {} diff --git a/vendor/thiserror/src/lib.rs b/vendor/thiserror/src/lib.rs index 247199ffd..aae6552d0 100644 --- a/vendor/thiserror/src/lib.rs +++ b/vendor/thiserror/src/lib.rs @@ -146,8 +146,9 @@ //! # } //! ``` //! -//! - The Error trait's `backtrace()` method is implemented to return whichever -//! field has a type named `Backtrace`, if any. +//! - The Error trait's `provide()` method is implemented to provide whichever +//! field has a type named `Backtrace`, if any, as a +//! `std::backtrace::Backtrace`. //! //! ```rust //! # const IGNORE: &str = stringify! { @@ -163,7 +164,8 @@ //! //! - If a field is both a source (named `source`, or has `#[source]` or //! `#[from]` attribute) *and* is marked `#[backtrace]`, then the Error -//! trait's `backtrace()` method is forwarded to the source's backtrace. +//! trait's `provide()` method is forwarded to the source's `provide` so that +//! both layers of the error share the same backtrace. //! //! ```rust //! # const IGNORE: &str = stringify! { @@ -196,6 +198,31 @@ //! } //! ``` //! +//! Another use case is hiding implementation details of an error +//! representation behind an opaque error type, so that the representation is +//! able to evolve without breaking the crate's public API. +//! +//! ``` +//! # use thiserror::Error; +//! # +//! // PublicError is public, but opaque and easy to keep compatible. +//! #[derive(Error, Debug)] +//! #[error(transparent)] +//! pub struct PublicError(#[from] ErrorRepr); +//! +//! impl PublicError { +//! // Accessors for anything we do want to expose publicly. +//! } +//! +//! // Private and free to change across minor version of the crate. +//! #[derive(Error, Debug)] +//! enum ErrorRepr { +//! # /* +//! ... +//! # */ +//! } +//! ``` +//! //! - See also the [`anyhow`] library for a convenient single error type to use //! in application code. //! @@ -206,10 +233,14 @@ clippy::doc_markdown, clippy::module_name_repetitions, clippy::return_self_not_must_use, + clippy::wildcard_imports, )] +#![cfg_attr(provide_any, feature(provide_any))] mod aserror; mod display; +#[cfg(provide_any)] +mod provide; pub use thiserror_impl::*; @@ -218,4 +249,6 @@ pub use thiserror_impl::*; pub mod __private { pub use crate::aserror::AsDynError; pub use crate::display::{DisplayAsDisplay, PathAsDisplay}; + #[cfg(provide_any)] + pub use crate::provide::ThiserrorProvide; } diff --git a/vendor/thiserror/src/provide.rs b/vendor/thiserror/src/provide.rs new file mode 100644 index 000000000..524e7435d --- /dev/null +++ b/vendor/thiserror/src/provide.rs @@ -0,0 +1,15 @@ +use std::any::{Demand, Provider}; + +pub trait ThiserrorProvide: Sealed { + fn thiserror_provide<'a>(&'a self, demand: &mut Demand<'a>); +} + +impl<T: Provider + ?Sized> ThiserrorProvide for T { + #[inline] + fn thiserror_provide<'a>(&'a self, demand: &mut Demand<'a>) { + self.provide(demand); + } +} + +pub trait Sealed {} +impl<T: Provider + ?Sized> Sealed for T {} |