diff --git a/src/lib.rs b/src/lib.rs index a97d17e..82f276c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,21 @@ //! the `std::error::Error` trait. //! //! ``` +//! # pub trait Deserialize {} +//! # +//! # mod serde_json { +//! # use super::Deserialize; +//! # use std::io; +//! # +//! # pub fn from_str(json: &str) -> io::Result { +//! # unimplemented!() +//! # } +//! # } +//! # +//! # struct ClusterMap; +//! # +//! # impl Deserialize for ClusterMap {} +//! # //! use anyhow::Result; //! //! fn get_cluster_info() -> Result { @@ -19,6 +34,8 @@ //! let map: ClusterMap = serde_json::from_str(&config)?; //! Ok(map) //! } +//! # +//! # fn main() {} //! ``` //! //! - Attach context to help the person troubleshooting the error understand @@ -27,15 +44,36 @@ //! level step the application was in the middle of. //! //! ``` +//! # struct It; +//! # +//! # impl It { +//! # fn detach(&self) -> Result<()> { +//! # unimplemented!() +//! # } +//! # } +//! # //! use anyhow::{Context, Result}; //! //! fn main() -> Result<()> { +//! # return Ok(()); +//! # +//! # const _: &str = stringify! { //! ... +//! # }; +//! # +//! # let it = It; +//! # let path = "./path/to/instrs.jsox"; +//! # //! it.detach().context("failed to detach the important thing")?; //! //! let content = std::fs::read(path) //! .with_context(|| format!("failed to read instrs from {}", path))?; +//! # +//! # const _: &str = stringify! { //! ... +//! # }; +//! # +//! # Ok(()) //! } //! ``` //! @@ -50,12 +88,36 @@ //! mutable reference as needed. //! //! ``` +//! # use anyhow::anyhow; +//! # use std::fmt::{self, Display}; +//! # use std::task::Poll; +//! # +//! # #[derive(Debug)] +//! # enum DataStoreError { +//! # Censored(()), +//! # } +//! # +//! # impl Display for DataStoreError { +//! # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { +//! # unimplemented!() +//! # } +//! # } +//! # +//! # impl std::error::Error for DataStoreError {} +//! # +//! # const REDACTED_CONTENT: () = (); +//! # +//! # let error = anyhow!("..."); +//! # let root_cause = &error; +//! # +//! # let ret = //! // If the error was caused by redaction, then return a //! // tombstone instead of the content. //! match root_cause.downcast_ref::() { -//! Some(DataStoreError::Censored(_)) => Ok(Async::Ready(REDACTED_CONTENT)), -//! None => Err(e), +//! Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)), +//! None => Err(error), //! } +//! # ; //! ``` //! //! - A backtrace is captured and printed with the error if the underlying error