mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-29 22:11:55 +00:00
Rename Context trait
This commit is contained in:
parent
86da223cde
commit
c476a98f77
@ -43,7 +43,7 @@ eyre = "1.0"
|
||||
application was in the middle of.
|
||||
|
||||
```rust
|
||||
use eyre::{Context, Result};
|
||||
use eyre::{Report, Result};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
...
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::error::ContextError;
|
||||
use crate::{Context, ErrReport, StdError};
|
||||
use crate::{Report, ErrReport, StdError};
|
||||
use core::convert::Infallible;
|
||||
use core::fmt::{self, Debug, Display, Write};
|
||||
|
||||
@ -39,7 +39,7 @@ mod ext {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> Context<T, E> for Result<T, E>
|
||||
impl<T, E> Report<T, E> for Result<T, E>
|
||||
where
|
||||
E: ext::StdError + Send + Sync + 'static,
|
||||
{
|
||||
@ -62,7 +62,7 @@ where
|
||||
/// ```
|
||||
/// # type T = ();
|
||||
/// #
|
||||
/// use eyre::{Context, Result};
|
||||
/// use eyre::{Report, Result};
|
||||
///
|
||||
/// fn maybe_get() -> Option<T> {
|
||||
/// # const IGNORE: &str = stringify! {
|
||||
@ -79,7 +79,7 @@ where
|
||||
/// # unimplemented!()
|
||||
/// }
|
||||
/// ```
|
||||
impl<T> Context<T, Infallible> for Option<T> {
|
||||
impl<T> Report<T, Infallible> for Option<T> {
|
||||
fn context<C>(self, context: C) -> Result<T, ErrReport>
|
||||
where
|
||||
C: Display + Send + Sync + 'static,
|
||||
|
@ -208,11 +208,11 @@ impl ErrReport {
|
||||
/// Wrap the error value with additional context.
|
||||
///
|
||||
/// For attaching context to a `Result` as it is propagated, the
|
||||
/// [`Context`][crate::Context] extension trait may be more convenient than
|
||||
/// [`Report`][crate::Report] extension trait may be more convenient than
|
||||
/// this function.
|
||||
///
|
||||
/// The primary reason to use `error.context(...)` instead of
|
||||
/// `result.context(...)` via the `Context` trait would be if the context
|
||||
/// `result.context(...)` via the `Report` trait would be if the context
|
||||
/// needs to depend on some data held by the underlying error:
|
||||
///
|
||||
/// ```
|
||||
@ -349,7 +349,7 @@ impl ErrReport {
|
||||
/// context has been attached. For details about the interaction between
|
||||
/// context and downcasting, [see here].
|
||||
///
|
||||
/// [see here]: trait.Context.html#effect-on-downcasting
|
||||
/// [see here]: trait.Report.html#effect-on-downcasting
|
||||
pub fn is<E>(&self) -> bool
|
||||
where
|
||||
E: Display + Debug + Send + Sync + 'static,
|
||||
|
16
src/lib.rs
16
src/lib.rs
@ -52,7 +52,7 @@
|
||||
//! # }
|
||||
//! # }
|
||||
//! #
|
||||
//! use eyre::{Context, Result};
|
||||
//! use eyre::{Report, Result};
|
||||
//!
|
||||
//! fn main() -> Result<()> {
|
||||
//! # return Ok(());
|
||||
@ -273,7 +273,7 @@ pub use eyre as format_err;
|
||||
/// at /git/eyre/src/backtrace.rs:26
|
||||
/// 1: core::result::Result<T,E>::map_err
|
||||
/// at /git/rustc/src/libcore/result.rs:596
|
||||
/// 2: eyre::context::<impl eyre::Context<T,E> for core::result::Result<T,E>>::with_context
|
||||
/// 2: eyre::context::<impl eyre::Report<T,E> for core::result::Result<T,E>>::with_context
|
||||
/// at /git/eyre/src/context.rs:58
|
||||
/// 3: testing::main
|
||||
/// at src/main.rs:5
|
||||
@ -302,7 +302,7 @@ pub use eyre as format_err;
|
||||
/// like this:
|
||||
///
|
||||
/// ```
|
||||
/// use eyre::{Context, Result};
|
||||
/// use eyre::{Report, Result};
|
||||
///
|
||||
/// fn main() {
|
||||
/// if let Err(err) = try_main() {
|
||||
@ -352,7 +352,7 @@ pub struct Chain<'a> {
|
||||
///
|
||||
/// This is a reasonable return type to use throughout your application but also
|
||||
/// for `fn main`; if you do, failures will be printed along with any
|
||||
/// [context][Context] and a backtrace if one was captured.
|
||||
/// [context][Report] and a backtrace if one was captured.
|
||||
///
|
||||
/// `eyre::Result` may be used with one *or* two type parameters.
|
||||
///
|
||||
@ -409,7 +409,7 @@ pub type Result<T, E = ErrReport> = core::result::Result<T, E>;
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use eyre::{Context, Result};
|
||||
/// use eyre::{Report, Result};
|
||||
/// use std::fs;
|
||||
/// use std::path::PathBuf;
|
||||
///
|
||||
@ -479,7 +479,7 @@ pub type Result<T, E = ErrReport> = core::result::Result<T, E>;
|
||||
/// # bail!(SuspiciousError);
|
||||
/// # }
|
||||
/// #
|
||||
/// use eyre::{Context, Result};
|
||||
/// use eyre::{Report, Result};
|
||||
///
|
||||
/// fn do_it() -> Result<()> {
|
||||
/// helper().context("Failed to complete the work")?;
|
||||
@ -519,7 +519,7 @@ pub type Result<T, E = ErrReport> = core::result::Result<T, E>;
|
||||
/// # bail!("no such file or directory");
|
||||
/// # }
|
||||
/// #
|
||||
/// use eyre::{Context, Result};
|
||||
/// use eyre::{Report, Result};
|
||||
///
|
||||
/// fn do_it() -> Result<()> {
|
||||
/// helper().context(HelperFailed)?;
|
||||
@ -540,7 +540,7 @@ pub type Result<T, E = ErrReport> = core::result::Result<T, E>;
|
||||
/// # panic!("expected downcast to succeed");
|
||||
/// }
|
||||
/// ```
|
||||
pub trait Context<T, E>: context::private::Sealed {
|
||||
pub trait Report<T, E>: context::private::Sealed {
|
||||
/// Wrap the error value with additional context.
|
||||
fn context<C>(self, context: C) -> Result<T, ErrReport>
|
||||
where
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod drop;
|
||||
|
||||
use crate::drop::{DetectDrop, Flag};
|
||||
use eyre::{Context, ErrReport, Result};
|
||||
use eyre::{Report, ErrReport, Result};
|
||||
use std::fmt::{self, Display};
|
||||
use thiserror::Error;
|
||||
|
||||
@ -68,7 +68,7 @@ fn make_chain() -> (ErrReport, Dropped) {
|
||||
drop: DetectDrop::new(&dropped.low),
|
||||
};
|
||||
|
||||
// impl Context for Result<T, E>
|
||||
// impl Report for Result<T, E>
|
||||
let mid = Err::<(), LowLevel>(low)
|
||||
.context(MidLevel {
|
||||
message: "failed to load config",
|
||||
@ -76,7 +76,7 @@ fn make_chain() -> (ErrReport, Dropped) {
|
||||
})
|
||||
.unwrap_err();
|
||||
|
||||
// impl Context for Result<T, Error>
|
||||
// impl Report for Result<T, Error>
|
||||
let high = Err::<(), ErrReport>(mid)
|
||||
.context(HighLevel {
|
||||
message: "failed to start server",
|
||||
|
@ -1,4 +1,4 @@
|
||||
use eyre::{bail, Context, Result};
|
||||
use eyre::{bail, Report, Result};
|
||||
use std::io;
|
||||
|
||||
fn f() -> Result<()> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user