Rename Context trait

This commit is contained in:
Jane Lusby 2020-02-27 13:18:06 -08:00
parent 86da223cde
commit c476a98f77
6 changed files with 20 additions and 20 deletions

View File

@ -43,7 +43,7 @@ eyre = "1.0"
application was in the middle of. application was in the middle of.
```rust ```rust
use eyre::{Context, Result}; use eyre::{Report, Result};
fn main() -> Result<()> { fn main() -> Result<()> {
... ...

View File

@ -1,5 +1,5 @@
use crate::error::ContextError; use crate::error::ContextError;
use crate::{Context, ErrReport, StdError}; use crate::{Report, ErrReport, StdError};
use core::convert::Infallible; use core::convert::Infallible;
use core::fmt::{self, Debug, Display, Write}; 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 where
E: ext::StdError + Send + Sync + 'static, E: ext::StdError + Send + Sync + 'static,
{ {
@ -62,7 +62,7 @@ where
/// ``` /// ```
/// # type T = (); /// # type T = ();
/// # /// #
/// use eyre::{Context, Result}; /// use eyre::{Report, Result};
/// ///
/// fn maybe_get() -> Option<T> { /// fn maybe_get() -> Option<T> {
/// # const IGNORE: &str = stringify! { /// # const IGNORE: &str = stringify! {
@ -79,7 +79,7 @@ where
/// # unimplemented!() /// # 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> fn context<C>(self, context: C) -> Result<T, ErrReport>
where where
C: Display + Send + Sync + 'static, C: Display + Send + Sync + 'static,

View File

@ -208,11 +208,11 @@ impl ErrReport {
/// Wrap the error value with additional context. /// Wrap the error value with additional context.
/// ///
/// For attaching context to a `Result` as it is propagated, the /// 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. /// this function.
/// ///
/// The primary reason to use `error.context(...)` instead of /// 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: /// 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 has been attached. For details about the interaction between
/// context and downcasting, [see here]. /// 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 pub fn is<E>(&self) -> bool
where where
E: Display + Debug + Send + Sync + 'static, E: Display + Debug + Send + Sync + 'static,

View File

@ -52,7 +52,7 @@
//! # } //! # }
//! # } //! # }
//! # //! #
//! use eyre::{Context, Result}; //! use eyre::{Report, Result};
//! //!
//! fn main() -> Result<()> { //! fn main() -> Result<()> {
//! # return Ok(()); //! # return Ok(());
@ -273,7 +273,7 @@ pub use eyre as format_err;
/// at /git/eyre/src/backtrace.rs:26 /// at /git/eyre/src/backtrace.rs:26
/// 1: core::result::Result<T,E>::map_err /// 1: core::result::Result<T,E>::map_err
/// at /git/rustc/src/libcore/result.rs:596 /// 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 /// at /git/eyre/src/context.rs:58
/// 3: testing::main /// 3: testing::main
/// at src/main.rs:5 /// at src/main.rs:5
@ -302,7 +302,7 @@ pub use eyre as format_err;
/// like this: /// like this:
/// ///
/// ``` /// ```
/// use eyre::{Context, Result}; /// use eyre::{Report, Result};
/// ///
/// fn main() { /// fn main() {
/// if let Err(err) = try_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 /// 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 /// 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. /// `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 /// # Example
/// ///
/// ``` /// ```
/// use eyre::{Context, Result}; /// use eyre::{Report, Result};
/// use std::fs; /// use std::fs;
/// use std::path::PathBuf; /// use std::path::PathBuf;
/// ///
@ -479,7 +479,7 @@ pub type Result<T, E = ErrReport> = core::result::Result<T, E>;
/// # bail!(SuspiciousError); /// # bail!(SuspiciousError);
/// # } /// # }
/// # /// #
/// use eyre::{Context, Result}; /// use eyre::{Report, Result};
/// ///
/// fn do_it() -> Result<()> { /// fn do_it() -> Result<()> {
/// helper().context("Failed to complete the work")?; /// 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"); /// # bail!("no such file or directory");
/// # } /// # }
/// # /// #
/// use eyre::{Context, Result}; /// use eyre::{Report, Result};
/// ///
/// fn do_it() -> Result<()> { /// fn do_it() -> Result<()> {
/// helper().context(HelperFailed)?; /// helper().context(HelperFailed)?;
@ -540,7 +540,7 @@ pub type Result<T, E = ErrReport> = core::result::Result<T, E>;
/// # panic!("expected downcast to succeed"); /// # 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. /// Wrap the error value with additional context.
fn context<C>(self, context: C) -> Result<T, ErrReport> fn context<C>(self, context: C) -> Result<T, ErrReport>
where where

View File

@ -1,7 +1,7 @@
mod drop; mod drop;
use crate::drop::{DetectDrop, Flag}; use crate::drop::{DetectDrop, Flag};
use eyre::{Context, ErrReport, Result}; use eyre::{Report, ErrReport, Result};
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use thiserror::Error; use thiserror::Error;
@ -68,7 +68,7 @@ fn make_chain() -> (ErrReport, Dropped) {
drop: DetectDrop::new(&dropped.low), drop: DetectDrop::new(&dropped.low),
}; };
// impl Context for Result<T, E> // impl Report for Result<T, E>
let mid = Err::<(), LowLevel>(low) let mid = Err::<(), LowLevel>(low)
.context(MidLevel { .context(MidLevel {
message: "failed to load config", message: "failed to load config",
@ -76,7 +76,7 @@ fn make_chain() -> (ErrReport, Dropped) {
}) })
.unwrap_err(); .unwrap_err();
// impl Context for Result<T, Error> // impl Report for Result<T, Error>
let high = Err::<(), ErrReport>(mid) let high = Err::<(), ErrReport>(mid)
.context(HighLevel { .context(HighLevel {
message: "failed to start server", message: "failed to start server",

View File

@ -1,4 +1,4 @@
use eyre::{bail, Context, Result}; use eyre::{bail, Report, Result};
use std::io; use std::io;
fn f() -> Result<()> { fn f() -> Result<()> {