mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-27 04:50:50 +00:00
Rename as_error to as_dyn_error
This commit is contained in:
parent
eac05d1c69
commit
895d3834e5
30
src/as_dyn_error.rs
Normal file
30
src/as_dyn_error.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use std::error::Error as StdError;
|
||||
|
||||
use crate::Error;
|
||||
|
||||
/// View error as a `&dyn std::error::Error`.
|
||||
pub trait AsDynError {
|
||||
/// View type as an error object.
|
||||
fn as_dyn_error(&self) -> &(dyn StdError + Send + Sync + 'static);
|
||||
}
|
||||
|
||||
impl<T> AsDynError for T
|
||||
where
|
||||
T: StdError + Send + Sync + 'static,
|
||||
{
|
||||
fn as_dyn_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsDynError for dyn StdError + Send + Sync + 'static {
|
||||
fn as_dyn_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsDynError for Error {
|
||||
fn as_dyn_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
&**self
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
use std::error::Error as StdError;
|
||||
|
||||
use crate::Error;
|
||||
|
||||
/// View type as an error object.
|
||||
pub trait AsError {
|
||||
/// View type as an error object.
|
||||
fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static);
|
||||
}
|
||||
|
||||
impl<T> AsError for T
|
||||
where
|
||||
T: StdError + Send + Sync + 'static,
|
||||
{
|
||||
fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsError for dyn StdError + Send + Sync + 'static {
|
||||
fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsError for Error {
|
||||
fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
&**self
|
||||
}
|
||||
}
|
@ -67,12 +67,12 @@ impl Error {
|
||||
}
|
||||
|
||||
/// View this error object as the underlying error.
|
||||
pub fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
pub fn as_dyn_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
|
||||
&**self
|
||||
}
|
||||
|
||||
/// View this error object as the underlying error, mutably.
|
||||
pub fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
|
||||
pub fn as_dyn_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
|
||||
&mut **self
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
#![feature(backtrace)]
|
||||
|
||||
mod as_error;
|
||||
mod as_dyn_error;
|
||||
mod context;
|
||||
mod error;
|
||||
|
||||
pub use crate::as_error::AsError;
|
||||
pub use crate::as_dyn_error::AsDynError;
|
||||
pub use crate::context::Context;
|
||||
pub use crate::error::{Error, Errors};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user