/// Construct an ad-hoc error from a string or existing non-`anyhow` error /// value. /// /// This evaluates to an [`Error`][crate::Error]. It can take either just a /// string, or a format string with arguments. It also can take any custom type /// which implements `Debug` and `Display`. /// /// If called with a single argument whose type implements `std::error::Error` /// (in addition to `Debug` and `Display`, which are always required), then that /// Error impl's `source` is preserved as the `source` of the resulting /// `anyhow::Error`. /// /// # Example /// /// ``` /// # type V = (); /// # /// use anyhow::{anyhow, Result}; /// /// fn lookup(key: &str) -> Result<V> { /// if key.len() != 16 { /// return Err(anyhow!("key length must be 16 characters, got {:?}", key)); /// } /// /// // ... /// # Ok(()) /// } /// ``` #[macro_export]
macro_rules! anyhow {
($msg:literal $(,)?) => {
$crate::__private::must_use({ let error = $crate::__private::format_err($crate::__private::format_args!($msg));
error
})
};
($err:expr $(,)?) => {
$crate::__private::must_use({ use $crate::__private::kind::*; let error = match $err {
error => (&error).anyhow_kind().new(error),
};
error
})
};
($fmt:expr, $($arg:tt)*) => {
$crate::Error::msg($crate::__private::format!($fmt, $($arg)*))
};
}
// Not public API. This is used in the implementation of some of the other // macros, in which the must_use call is not needed because the value is known // to be used. #[doc(hidden)] #[macro_export]
macro_rules! __anyhow {
($msg:literal $(,)?) => ({ let error = $crate::__private::format_err($crate::__private::format_args!($msg));
error
});
($err:expr $(,)?) => ({ use $crate::__private::kind::*; let error = match $err {
error => (&error).anyhow_kind().new(error),
};
error
});
($fmt:expr, $($arg:tt)*) => {
$crate::Error::msg($crate::__private::format!($fmt, $($arg)*))
};
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.