lib.rs
This file
Path
src/lib.rs
695 lines · 20.2 KiB · Rust
Last changed by
Release 1.0.76David Tolnaybefore adoption5cad3bf
History of this fileTake it
The walk stopped after 200 commits: lines older than b45d649 point at it.
Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 1–4why, one step back1//! [![github]](https://github.com/dtolnay/anyhow) [![crates-io]](https://crates.io/crates/anyhow) [![docs-rs]](https://docs.rs/anyhow)2//!3//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github4//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rustUse upstreamed docs.rs icon in docs.rs badgeDavid Tolnaybefore adoptiond8c2388
line 5why, one step back5//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rsIgnore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 6–130why, one step back6//!7//! <br>8//!9//! This library provides [`anyhow::Error`][Error], a trait object based error10//! type for easy idiomatic error handling in Rust applications.11//!12//! <br>13//!14//! # Details15//!16//! - Use `Result<T, anyhow::Error>`, or equivalently `anyhow::Result<T>`, as17//! the return type of any fallible function.18//!19//! Within the function, use `?` to easily propagate any error that implements20//! the `std::error::Error` trait.21//!22//! ```23//! # pub trait Deserialize {}24//! #25//! # mod serde_json {26//! # use super::Deserialize;27//! # use std::io;28//! #29//! # pub fn from_str<T: Deserialize>(json: &str) -> io::Result<T> {30//! # unimplemented!()31//! # }32//! # }33//! #34//! # struct ClusterMap;35//! #36//! # impl Deserialize for ClusterMap {}37//! #38//! use anyhow::Result;39//!40//! fn get_cluster_info() -> Result<ClusterMap> {41//! let config = std::fs::read_to_string("cluster.json")?;42//! let map: ClusterMap = serde_json::from_str(&config)?;43//! Ok(map)44//! }45//! #46//! # fn main() {}47//! ```48//!49//! - Attach context to help the person troubleshooting the error understand50//! where things went wrong. A low-level error like "No such file or51//! directory" can be annoying to debug without more context about what higher52//! level step the application was in the middle of.53//!54//! ```55//! # struct It;56//! #57//! # impl It {58//! # fn detach(&self) -> Result<()> {59//! # unimplemented!()60//! # }61//! # }62//! #63//! use anyhow::{Context, Result};64//!65//! fn main() -> Result<()> {66//! # return Ok(());67//! #68//! # const _: &str = stringify! {69//! ...70//! # };71//! #72//! # let it = It;73//! # let path = "./path/to/instrs.json";74//! #75//! it.detach().context("Failed to detach the important thing")?;76//!77//! let content = std::fs::read(path)78//! .with_context(|| format!("Failed to read instrs from {}", path))?;79//! #80//! # const _: &str = stringify! {81//! ...82//! # };83//! #84//! # Ok(())85//! }86//! ```87//!88//! ```console89//! Error: Failed to read instrs from ./path/to/instrs.json90//!91//! Caused by:92//! No such file or directory (os error 2)93//! ```94//!95//! - Downcasting is supported and can be by value, by shared reference, or by96//! mutable reference as needed.97//!98//! ```99//! # use anyhow::anyhow;100//! # use std::fmt::{self, Display};101//! # use std::task::Poll;102//! #103//! # #[derive(Debug)]104//! # enum DataStoreError {105//! # Censored(()),106//! # }107//! #108//! # impl Display for DataStoreError {109//! # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {110//! # unimplemented!()111//! # }112//! # }113//! #114//! # impl std::error::Error for DataStoreError {}115//! #116//! # const REDACTED_CONTENT: () = ();117//! #118//! # let error = anyhow!("...");119//! # let root_cause = &error;120//! #121//! # let ret =122//! // If the error was caused by redaction, then return a123//! // tombstone instead of the content.124//! match root_cause.downcast_ref::<DataStoreError>() {125//! Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),126//! None => Err(error),127//! }128//! # ;129//! ```130//!Mirror PR 162 from readme to rustdocDavid Tolnaybefore adoptionb3c5e25
lines 131–135why, one step back131//! - If using the nightly channel, or stable with `features = ["backtrace"]`, a132//! backtrace is captured and printed with the error if the underlying error133//! type does not already provide its own. In order to see backtraces, they134//! must be enabled through the environment variables described in135//! [`std::backtrace`]:Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 136–212why, one step back136//!137//! - If you want panics and errors to both have backtraces, set138//! `RUST_BACKTRACE=1`;139//! - If you want only errors to have backtraces, set `RUST_LIB_BACKTRACE=1`;140//! - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and141//! `RUST_LIB_BACKTRACE=0`.142//!143//! The tracking issue for this feature is [rust-lang/rust#53487].144//!145//! [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables146//! [rust-lang/rust#53487]: https://github.com/rust-lang/rust/issues/53487147//!148//! - Anyhow works with any error type that has an impl of `std::error::Error`,149//! including ones defined in your crate. We do not bundle a `derive(Error)`150//! macro but you can write the impls yourself or use a standalone macro like151//! [thiserror].152//!153//! [thiserror]: https://github.com/dtolnay/thiserror154//!155//! ```156//! use thiserror::Error;157//!158//! #[derive(Error, Debug)]159//! pub enum FormatError {160//! #[error("Invalid header (expected {expected:?}, got {found:?})")]161//! InvalidHeader {162//! expected: String,163//! found: String,164//! },165//! #[error("Missing attribute: {0}")]166//! MissingAttribute(String),167//! }168//! ```169//!170//! - One-off error messages can be constructed using the `anyhow!` macro, which171//! supports string interpolation and produces an `anyhow::Error`.172//!173//! ```174//! # use anyhow::{anyhow, Result};175//! #176//! # fn demo() -> Result<()> {177//! # let missing = "...";178//! return Err(anyhow!("Missing attribute: {}", missing));179//! # Ok(())180//! # }181//! ```182//!183//! A `bail!` macro is provided as a shorthand for the same early return.184//!185//! ```186//! # use anyhow::{bail, Result};187//! #188//! # fn demo() -> Result<()> {189//! # let missing = "...";190//! bail!("Missing attribute: {}", missing);191//! # Ok(())192//! # }193//! ```194//!195//! <br>196//!197//! # No-std support198//!199//! In no_std mode, the same API is almost all available and works the same way.200//! To depend on Anyhow in no_std mode, disable our default enabled "std"201//! feature in Cargo.toml. A global allocator is required.202//!203//! ```toml204//! [dependencies]205//! anyhow = { version = "1.0", default-features = false }206//! ```207//!208//! Since the `?`-based error conversions would normally rely on the209//! `std::error::Error` trait which is only available through std, no_std mode210//! will require an explicit `.map_err(Error::msg)` when working with a211//! non-Anyhow error type inside a function that returns Anyhow's error type.212Release 1.0.76David Tolnaybefore adoption5cad3bf
line 213why, one step back213#![doc(html_root_url = "https://docs.rs/anyhow/1.0.76")]Merge pull request #319 from dtolnay/errorprovideDavid Tolnaybefore adoption8cf1d15
line 214why, one step back214#![cfg_attr(backtrace, feature(error_generic_member_access))]Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 215–217why, one step back215#![cfg_attr(doc_cfg, feature(doc_cfg))]216#![cfg_attr(not(feature = "std"), no_std)]217#![deny(dead_code, unused_imports, unused_mut)]Merge pull request #329 from dtolnay/unsafeopDavid Tolnaybefore adoptiond371a49
lines 218–222why, one step back218#![cfg_attr(219 not(anyhow_no_unsafe_op_in_unsafe_fn_lint),220 deny(unsafe_op_in_unsafe_fn)221)]222#![cfg_attr(anyhow_no_unsafe_op_in_unsafe_fn_lint, allow(unused_unsafe))]Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 223–225why, one step back223#![allow(224 clippy::doc_markdown,225 clippy::enum_glob_use,Ignore explicit_auto_deref clippy lintDavid Tolnaybefore adoption38c883b
line 226why, one step back226 clippy::explicit_auto_deref,Ignore extra_unused_type_parameters clippy lint in testDavid Tolnaybefore adoptione0292fe
line 227why, one step back227 clippy::extra_unused_type_parameters,Ignore let_underscore_untyped pedantic clippy lintDavid Tolnaybefore adoptiond30b027
line 228why, one step back228 clippy::let_underscore_untyped,Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 229–235why, one step back229 clippy::missing_errors_doc,230 clippy::missing_panics_doc,231 clippy::module_name_repetitions,232 clippy::must_use_candidate,233 clippy::needless_doctest_main,234 clippy::new_ret_no_self,235 clippy::redundant_else,Ignore return_self_not_must_use clippy lintDavid Tolnaybefore adoptiona3f7160
line 236why, one step back236 clippy::return_self_not_must_use,Ignore struct_field_names pedantic clippy lintDavid Tolnaybefore adoption05e4132
line 237why, one step back237 clippy::struct_field_names,Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 238–243why, one step back238 clippy::unused_self,239 clippy::used_underscore_binding,240 clippy::wildcard_imports,241 clippy::wrong_self_convention242)]243Merge pull request #178 from dtolnay/upDavid Tolnaybefore adoption3c586dd
line 244why, one step back244extern crate alloc;Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 245–249why, one step back245246#[macro_use]247mod backtrace;248mod chain;249mod context;Merge pull request #193 from dtolnay/ensureDavid Tolnaybefore adoptione05df5f
line 250why, one step back250mod ensure;Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 251–274why, one step back251mod error;252mod fmt;253mod kind;254mod macros;255mod ptr;256mod wrapper;257258use crate::error::ErrorImpl;259use crate::ptr::Own;260use core::fmt::Display;261262#[cfg(not(feature = "std"))]263use core::fmt::Debug;264265#[cfg(feature = "std")]266use std::error::Error as StdError;267268#[cfg(not(feature = "std"))]269trait StdError: Debug + Display {270 fn source(&self) -> Option<&(dyn StdError + 'static)> {271 None272 }273}274Merge pull request #306 from dtolnay/noinlineDavid Tolnaybefore adoption3c33b4b
line 275why, one step back275#[doc(no_inline)]Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 276–378why, one step back276pub use anyhow as format_err;277278/// The `Error` type, a wrapper around a dynamic error type.279///280/// `Error` works a lot like `Box<dyn std::error::Error>`, but with these281/// differences:282///283/// - `Error` requires that the error is `Send`, `Sync`, and `'static`.284/// - `Error` guarantees that a backtrace is available, even if the underlying285/// error type does not provide one.286/// - `Error` is represented as a narrow pointer — exactly one word in287/// size instead of two.288///289/// <br>290///291/// # Display representations292///293/// When you print an error object using "{}" or to_string(), only the outermost294/// underlying error or context is printed, not any of the lower level causes.295/// This is exactly as if you had called the Display impl of the error from296/// which you constructed your anyhow::Error.297///298/// ```console299/// Failed to read instrs from ./path/to/instrs.json300/// ```301///302/// To print causes as well using anyhow's default formatting of causes, use the303/// alternate selector "{:#}".304///305/// ```console306/// Failed to read instrs from ./path/to/instrs.json: No such file or directory (os error 2)307/// ```308///309/// The Debug format "{:?}" includes your backtrace if one was captured. Note310/// that this is the representation you get by default if you return an error311/// from `fn main` instead of printing it explicitly yourself.312///313/// ```console314/// Error: Failed to read instrs from ./path/to/instrs.json315///316/// Caused by:317/// No such file or directory (os error 2)318/// ```319///320/// and if there is a backtrace available:321///322/// ```console323/// Error: Failed to read instrs from ./path/to/instrs.json324///325/// Caused by:326/// No such file or directory (os error 2)327///328/// Stack backtrace:329/// 0: <E as anyhow::context::ext::StdError>::ext_context330/// at /git/anyhow/src/backtrace.rs:26331/// 1: core::result::Result<T,E>::map_err332/// at /git/rustc/src/libcore/result.rs:596333/// 2: anyhow::context::<impl anyhow::Context<T,E> for core::result::Result<T,E>>::with_context334/// at /git/anyhow/src/context.rs:58335/// 3: testing::main336/// at src/main.rs:5337/// 4: std::rt::lang_start338/// at /git/rustc/src/libstd/rt.rs:61339/// 5: main340/// 6: __libc_start_main341/// 7: _start342/// ```343///344/// To see a conventional struct-style Debug representation, use "{:#?}".345///346/// ```console347/// Error {348/// context: "Failed to read instrs from ./path/to/instrs.json",349/// source: Os {350/// code: 2,351/// kind: NotFound,352/// message: "No such file or directory",353/// },354/// }355/// ```356///357/// If none of the built-in representations are appropriate and you would prefer358/// to render the error and its cause chain yourself, it can be done something359/// like this:360///361/// ```362/// use anyhow::{Context, Result};363///364/// fn main() {365/// if let Err(err) = try_main() {366/// eprintln!("ERROR: {}", err);367/// err.chain().skip(1).for_each(|cause| eprintln!("because: {}", cause));368/// std::process::exit(1);369/// }370/// }371///372/// fn try_main() -> Result<()> {373/// # const IGNORE: &str = stringify! {374/// ...375/// # };376/// # Ok(())377/// }378/// ```Merge pull request #295 from dtolnay/docreprDavid Tolnaybefore adoptionf65b087
line 379why, one step back379#[cfg_attr(not(doc), repr(transparent))]Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 380–508why, one step back380pub struct Error {381 inner: Own<ErrorImpl>,382}383384/// Iterator of a chain of source errors.385///386/// This type is the iterator returned by [`Error::chain`].387///388/// # Example389///390/// ```391/// use anyhow::Error;392/// use std::io;393///394/// pub fn underlying_io_error_kind(error: &Error) -> Option<io::ErrorKind> {395/// for cause in error.chain() {396/// if let Some(io_error) = cause.downcast_ref::<io::Error>() {397/// return Some(io_error.kind());398/// }399/// }400/// None401/// }402/// ```403#[cfg(feature = "std")]404#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]405#[derive(Clone)]406pub struct Chain<'a> {407 state: crate::chain::ChainState<'a>,408}409410/// `Result<T, Error>`411///412/// This is a reasonable return type to use throughout your application but also413/// for `fn main`; if you do, failures will be printed along with any414/// [context][Context] and a backtrace if one was captured.415///416/// `anyhow::Result` may be used with one *or* two type parameters.417///418/// ```rust419/// use anyhow::Result;420///421/// # const IGNORE: &str = stringify! {422/// fn demo1() -> Result<T> {...}423/// // ^ equivalent to std::result::Result<T, anyhow::Error>424///425/// fn demo2() -> Result<T, OtherError> {...}426/// // ^ equivalent to std::result::Result<T, OtherError>427/// # };428/// ```429///430/// # Example431///432/// ```433/// # pub trait Deserialize {}434/// #435/// # mod serde_json {436/// # use super::Deserialize;437/// # use std::io;438/// #439/// # pub fn from_str<T: Deserialize>(json: &str) -> io::Result<T> {440/// # unimplemented!()441/// # }442/// # }443/// #444/// # #[derive(Debug)]445/// # struct ClusterMap;446/// #447/// # impl Deserialize for ClusterMap {}448/// #449/// use anyhow::Result;450///451/// fn main() -> Result<()> {452/// # return Ok(());453/// let config = std::fs::read_to_string("cluster.json")?;454/// let map: ClusterMap = serde_json::from_str(&config)?;455/// println!("cluster info: {:#?}", map);456/// Ok(())457/// }458/// ```459pub type Result<T, E = Error> = core::result::Result<T, E>;460461/// Provides the `context` method for `Result`.462///463/// This trait is sealed and cannot be implemented for types outside of464/// `anyhow`.465///466/// <br>467///468/// # Example469///470/// ```471/// use anyhow::{Context, Result};472/// use std::fs;473/// use std::path::PathBuf;474///475/// pub struct ImportantThing {476/// path: PathBuf,477/// }478///479/// impl ImportantThing {480/// # const IGNORE: &'static str = stringify! {481/// pub fn detach(&mut self) -> Result<()> {...}482/// # };483/// # fn detach(&mut self) -> Result<()> {484/// # unimplemented!()485/// # }486/// }487///488/// pub fn do_it(mut it: ImportantThing) -> Result<Vec<u8>> {489/// it.detach().context("Failed to detach the important thing")?;490///491/// let path = &it.path;492/// let content = fs::read(path)493/// .with_context(|| format!("Failed to read instrs from {}", path.display()))?;494///495/// Ok(content)496/// }497/// ```498///499/// When printed, the outermost context would be printed first and the lower500/// level underlying causes would be enumerated below.501///502/// ```console503/// Error: Failed to read instrs from ./path/to/instrs.json504///505/// Caused by:506/// No such file or directory (os error 2)507/// ```508///Add link from Context docs to Display representationsDavid Tolnaybefore adoption6a31772
lines 509–513why, one step back509/// Refer to the [Display representations] documentation for other forms in510/// which this context chain can be rendered.511///512/// [Display representations]: Error#display-representations513///Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 514–620why, one step back514/// <br>515///516/// # Effect on downcasting517///518/// After attaching context of type `C` onto an error of type `E`, the resulting519/// `anyhow::Error` may be downcast to `C` **or** to `E`.520///521/// That is, in codebases that rely on downcasting, Anyhow's context supports522/// both of the following use cases:523///524/// - **Attaching context whose type is insignificant onto errors whose type525/// is used in downcasts.**526///527/// In other error libraries whose context is not designed this way, it can528/// be risky to introduce context to existing code because new context might529/// break existing working downcasts. In Anyhow, any downcast that worked530/// before adding context will continue to work after you add a context, so531/// you should freely add human-readable context to errors wherever it would532/// be helpful.533///534/// ```535/// # use anyhow::bail;536/// # use thiserror::Error;537/// #538/// # #[derive(Error, Debug)]539/// # #[error("???")]540/// # struct SuspiciousError;541/// #542/// # fn helper() -> Result<()> {543/// # bail!(SuspiciousError);544/// # }545/// #546/// use anyhow::{Context, Result};547///548/// fn do_it() -> Result<()> {549/// helper().context("Failed to complete the work")?;550/// # const IGNORE: &str = stringify! {551/// ...552/// # };553/// # unreachable!()554/// }555///556/// fn main() {557/// let err = do_it().unwrap_err();558/// if let Some(e) = err.downcast_ref::<SuspiciousError>() {559/// // If helper() returned SuspiciousError, this downcast will560/// // correctly succeed even with the context in between.561/// # return;562/// }563/// # panic!("expected downcast to succeed");564/// }565/// ```566///567/// - **Attaching context whose type is used in downcasts onto errors whose568/// type is insignificant.**569///570/// Some codebases prefer to use machine-readable context to categorize571/// lower level errors in a way that will be actionable to higher levels of572/// the application.573///574/// ```575/// # use anyhow::bail;576/// # use thiserror::Error;577/// #578/// # #[derive(Error, Debug)]579/// # #[error("???")]580/// # struct HelperFailed;581/// #582/// # fn helper() -> Result<()> {583/// # bail!("no such file or directory");584/// # }585/// #586/// use anyhow::{Context, Result};587///588/// fn do_it() -> Result<()> {589/// helper().context(HelperFailed)?;590/// # const IGNORE: &str = stringify! {591/// ...592/// # };593/// # unreachable!()594/// }595///596/// fn main() {597/// let err = do_it().unwrap_err();598/// if let Some(e) = err.downcast_ref::<HelperFailed>() {599/// // If helper failed, this downcast will succeed because600/// // HelperFailed is the context that has been attached to601/// // that error.602/// # return;603/// }604/// # panic!("expected downcast to succeed");605/// }606/// ```607pub trait Context<T, E>: context::private::Sealed {608 /// Wrap the error value with additional context.609 fn context<C>(self, context: C) -> Result<T, Error>610 where611 C: Display + Send + Sync + 'static;612613 /// Wrap the error value with additional context that is evaluated lazily614 /// only once an error does occur.615 fn with_context<C, F>(self, f: F) -> Result<T, Error>616 where617 C: Display + Send + Sync + 'static,618 F: FnOnce() -> C;619}620Show doc for Ok fnDavid Tolnaybefore adoption97cff68
line 621why, one step back621/// Equivalent to Ok::<_, anyhow::Error>(value).Add anyhow::OkDavid Tolnaybefore adoption2d4bb64
lines 622–643why, one step back622///623/// This simplifies creation of an anyhow::Result in places where type inference624/// cannot deduce the `E` type of the result — without needing to write625/// `Ok::<_, anyhow::Error>(value)`.626///627/// One might think that `anyhow::Result::Ok(value)` would work in such cases628/// but it does not.629///630/// ```console631/// error[E0282]: type annotations needed for `std::result::Result<i32, E>`632/// --> src/main.rs:11:13633/// |634/// 11 | let _ = anyhow::Result::Ok(1);635/// | - ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the enum `Result`636/// | |637/// | consider giving this pattern the explicit type `std::result::Result<i32, E>`, where the type parameter `E` is specified638/// ```639#[allow(non_snake_case)]640pub fn Ok<T>(t: T) -> Result<T> {641 Result::Ok(t)642}643Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 644–645why, one step back644// Not public API. Referenced by macro-generated code.645#[doc(hidden)]Make private module more clearly privateDavid Tolnaybefore adoptionb88a699
line 646why, one step back646pub mod __private {Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
lines 647–648why, one step back647 use crate::Error;648 use alloc::fmt;Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089
line 649why, one step back649 use core::fmt::Arguments;Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
line 650why, one step back650Work around ridiculous rust-analyzer behaviorDavid Tolnaybefore adoption238223a
line 651why, one step back651 #[doc(hidden)]Merge pull request #193 from dtolnay/ensureDavid Tolnaybefore adoptione05df5f
line 652why, one step back652 pub use crate::ensure::{BothDebug, NotBothDebug};Work around ridiculous rust-analyzer behaviorDavid Tolnaybefore adoption238223a
line 653why, one step back653 #[doc(hidden)]Merge pull request #179 from dtolnay/upDavid Tolnaybefore adoptioncd03064
line 654why, one step back654 pub use alloc::format;Work around ridiculous rust-analyzer behaviorDavid Tolnaybefore adoption238223a
line 655why, one step back655 #[doc(hidden)]Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
line 656why, one step back656 pub use core::result::Result::Err;Work around ridiculous rust-analyzer behaviorDavid Tolnaybefore adoption238223a
line 657why, one step back657 #[doc(hidden)]Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
line 658why, one step back658 pub use core::{concat, format_args, stringify};Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 659–661why, one step back659660 #[doc(hidden)]661 pub mod kind {Work around ridiculous rust-analyzer behaviorDavid Tolnaybefore adoption238223a
line 662why, one step back662 #[doc(hidden)]Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
lines 663–665why, one step back663 pub use crate::kind::{AdhocKind, TraitKind};664665 #[cfg(feature = "std")]Work around ridiculous rust-analyzer behaviorDavid Tolnaybefore adoption238223a
line 666why, one step back666 #[doc(hidden)]Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
line 667why, one step back667 pub use crate::kind::BoxedKind;Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
lines 668–670why, one step back668 }669670 #[doc(hidden)]Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089
line 671why, one step back671 #[inline]Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
line 672why, one step back672 #[cold]Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089
line 673why, one step back673 pub fn format_err(args: Arguments) -> Error {Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
line 674why, one step back674 #[cfg(anyhow_no_fmt_arguments_as_str)]Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089
line 675why, one step back675 let fmt_arguments_as_str = None::<&str>;Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
line 676why, one step back676 #[cfg(not(anyhow_no_fmt_arguments_as_str))]Merge pull request #184 from dtolnay/escapeDavid Tolnaybefore adoption6c1fd34
line 677why, one step back677 let fmt_arguments_as_str = args.as_str();Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
line 678why, one step back678Merge pull request #184 from dtolnay/escapeDavid Tolnaybefore adoption6c1fd34
line 679why, one step back679 if let Some(message) = fmt_arguments_as_str {Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
lines 680–681why, one step back680 // anyhow!("literal"), can downcast to &'static str681 Error::msg(message)Merge pull request #184 from dtolnay/escapeDavid Tolnaybefore adoption6c1fd34
lines 682–684why, one step back682 } else {683 // anyhow!("interpolate {var}"), can downcast to String684 Error::msg(fmt::format(args))Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c
line 685why, one step back685 }Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
line 686why, one step back686 }Merge pull request #229 from dtolnay/must_useDavid Tolnaybefore adoptionc8a3e42
lines 687–694why, one step back687688 #[doc(hidden)]689 #[inline]690 #[cold]691 #[must_use]692 pub fn must_use(error: Error) -> Error {693 error694 }Ignore unhelpful Clippy lint in build scriptDavid Tolnaybefore adoptionb45d649
line 695why, one step back695}