AOQSHDBY3FLBJBFEIJQDYHGQOBECTYRN3KPWJWQMCVWDTB6L2IRQC
MCPTFJMN333Z2GVL5J2KPLR6BJ3TAZKUGFORXNZ4YZBRXVQLCMFQC
E54DU5UDWVAFMQOBDWIAXWUHXMPMZMWJI6RS7BHD74KULPP6AJRQC
ZWBKKVT5TX2CSMBVEYZMQ6DLCXVHSD7SWFEKXWK6XKD6RP24MJJAC
CITEDKPB6MKVZUEYEDE5ZKTNVY35HCOAXKDPYG7YLLEOVFNMSRXQC
ZDN7BJ3JA3VL4AYWX3SV24GHP6NCAETJVAKAXKMIZTLHTWLUNMOQC
KCOCFOS6KMCTVS6K3WE6KOQSWC3QNWN2E36ASHQPP3Z3H4BHR3NQC
KOSCTMZC6VWQ5WST25FPATUAFCYG3JZGG3LF6MXSS42GPGHLDREQC
PKQO3KS575PJOJMYKDOJFKWIXMXDUOMPKDFIG5PMFABXU4CYEOLQC
EXRAFG37562NH775A4LDPP5FNKXLPLIZSJ3FCOBINUDKRFBJHCXAC
UM7DFUYLW4HSMBUDZY3R6ZNJRSX2E75C4DYV3MJAU57EUCGE6JLAC
GZZOJ7ZUSBPI3HXIV5UCFNMCDAMZPPLISY2UDV73FDN74HZ3AWJAC
AP4JEVKMUJFBWFSOOSAYM3WHYPVNGQW2IMIQX3XXDER4OV4MYIIAC
RD65M7RC2QYSEEW6JJGAPGB4XB6MCXKMDNHA3EU3WECBOUYNLDVQC
BQU6MTEH6QEW5E2HX3F2AAZ54AHIVDVOEE7FTCQTPLO23U5ILFIQC
RTVLSOCCLZMZRJZXRIX5RHJMAFJO4XK573NXTBZVBEJSUBJPY5ZQC
KQXMNV3RMRPSJCQVW4I2HSCFJQ6ZDRLNMJOTQI4MODB6UYA3ONQQC
/// Provides the `context` method for `Result`.
///
/// This trait is sealed and cannot be implemented for types outside of
/// `anyhow`.
///
/// # Example
///
/// ```
/// use anyhow::{Context, Result};
/// use std::fs;
/// use std::path::PathBuf;
///
/// pub struct ImportantThing {
/// path: PathBuf,
/// }
///
/// impl ImportantThing {
/// # const IGNORE: &'static str = stringify! {
/// pub fn detach(&mut self) -> Result<()> {...}
/// # };
/// # fn detach(&mut self) -> Result<()> {
/// # unimplemented!()
/// # }
/// }
///
/// pub fn do_it(mut it: ImportantThing) -> Result<Vec<u8>> {
/// it.detach().context("failed to detach the important thing")?;
///
/// let path = &it.path;
/// let content = fs::read(path)
/// .with_context(|| format!("failed to read instrs from {}", path.display()))?;
///
/// Ok(content)
/// }
/// ```
///
/// When printed, the outermost context would be printed first and the lower
/// level underlying causes would be enumerated below.
///
/// ```console
/// Error: failed to read instrs from ./path/to/instrs.jsox
///
/// caused by:
/// No such file or directory (os error 2)
/// ```
pub trait Context<T, E>: private::Sealed {
/// Wrap the error value with additional context.
fn context<C>(self, context: C) -> Result<T, Error>
where
C: Display + Send + Sync + 'static;
/// Wrap the error value with additional context that is evaluated lazily
/// only once an error does occur.
fn with_context<C, F>(self, f: F) -> Result<T, Error>
where
C: Display + Send + Sync + 'static,
F: FnOnce() -> C;
}
}
/// Provides the `context` method for `Result`.
///
/// This trait is sealed and cannot be implemented for types outside of
/// `anyhow`.
///
/// # Example
///
/// ```
/// use anyhow::{Context, Result};
/// use std::fs;
/// use std::path::PathBuf;
///
/// pub struct ImportantThing {
/// path: PathBuf,
/// }
///
/// impl ImportantThing {
/// # const IGNORE: &'static str = stringify! {
/// pub fn detach(&mut self) -> Result<()> {...}
/// # };
/// # fn detach(&mut self) -> Result<()> {
/// # unimplemented!()
/// # }
/// }
///
/// pub fn do_it(mut it: ImportantThing) -> Result<Vec<u8>> {
/// it.detach().context("failed to detach the important thing")?;
///
/// let path = &it.path;
/// let content = fs::read(path)
/// .with_context(|| format!("failed to read instrs from {}", path.display()))?;
///
/// Ok(content)
/// }
/// ```
///
/// When printed, the outermost context would be printed first and the lower
/// level underlying causes would be enumerated below.
///
/// ```console
/// Error: failed to read instrs from ./path/to/instrs.jsox
///
/// caused by:
/// No such file or directory (os error 2)
/// ```
pub trait Context<T, E>: context::private::Sealed {
/// Wrap the error value with additional context.
fn context<C>(self, context: C) -> Result<T, Error>
where
C: Display + Send + Sync + 'static;
/// Wrap the error value with additional context that is evaluated lazily
/// only once an error does occur.
fn with_context<C, F>(self, f: F) -> Result<T, Error>
where
C: Display + Send + Sync + 'static,
F: FnOnce() -> C;