Skip to content

Commit

Permalink
Add trait with method that won't collide between Provider and Error
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 13, 2022
1 parent 293b127 commit 460396e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@
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::*;

Expand All @@ -219,4 +222,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;
}
15 changes: 15 additions & 0 deletions src/provide.rs
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 460396e

Please sign in to comment.