#[cfg_attr(
not(feature = "no-format-args-capture"),
doc = r#" bail!("permission denied for accessing {resource}");"#
)]
#[cfg_attr(
feature = "no-format-args-capture",
doc = r#" bail!("permission denied for accessing {}", resource);"#
)]
#[cfg_attr(
not(feature = "no-format-args-capture"),
doc = r#" "dividing by value ({y}) close to 0""#
)]
#[cfg_attr(
feature = "no-format-args-capture",
doc = r#" "dividing by value ({}) close to 0", y"#
)]
#[macro_export]
macro_rules! bail {
($($key:ident = $value:expr_2021,)* $fmt:literal $($arg:tt)*) => {
return $crate::private::Err(
$crate::miette!($($key = $value,)* $fmt $($arg)*)
);
};
($err:expr_2021 $(,)?) => {
return $crate::private::Err($crate::miette!($err));
};
}
#[cfg_attr(
not(feature = "no-format-args-capture"),
doc = r#" "dividing by value ({y}) close to 0""#
)]
#[cfg_attr(
feature = "no-format-args-capture",
doc = r#" "dividing by value ({}) close to 0", y"#
)]
#[macro_export]
macro_rules! ensure {
($cond:expr_2021, $($key:ident = $value:expr_2021,)* $fmt:literal $($arg:tt)*) => {
if !$cond {
return $crate::private::Err(
$crate::miette!($($key = $value,)* $fmt $($arg)*)
);
}
};
($cond:expr_2021, $err:expr_2021 $(,)?) => {
if !$cond {
return $crate::private::Err($crate::miette!($err));
}
};
}
#[cfg_attr(
not(feature = "no-format-args-capture"),
doc = r#"let report = miette!("{x} + {} = {z}", y, z = x + y);"#
)]
#[cfg_attr(
feature = "no-format-args-capture",
doc = r#"let report = miette!("{} + {} = {z}", x, y, z = x + y);"#
)]
#[cfg_attr(
not(feature = "no-format-args-capture"),
doc = r#"let report = miette!("{x} + {y} = {z}");"#
)]
#[cfg_attr(
feature = "no-format-args-capture",
doc = r#"let report = miette!("{} + {} = {}", x, y, z);"#
)]
#[macro_export]
macro_rules! miette {
($($key:ident = $value:expr_2021,)* $fmt:literal $($arg:tt)*) => {
$crate::Report::from(
$crate::diagnostic!($($key = $value,)* $fmt $($arg)*)
)
};
($err:expr_2021 $(,)?) => ({
use $crate::private::kind::*;
let error = $err;
(&error).miette_kind().new(error)
});
}
#[cfg_attr(
not(feature = "no-format-args-capture"),
doc = r#" let diag = diagnostic!("{x} + {} = {z}", y, z = x + y);"#
)]
#[cfg_attr(
feature = "no-format-args-capture",
doc = r#" let diag = diagnostic!("{} + {} = {z}", x, y, z = x + y);"#
)]
#[cfg_attr(
not(feature = "no-format-args-capture"),
doc = r#"let diag = diagnostic!("{x} + {y} = {z}");"#
)]
#[cfg_attr(
feature = "no-format-args-capture",
doc = r#"let diag = diagnostic!("{} + {} = {}", x, y, z);"#
)]
#[macro_export]
macro_rules! diagnostic {
($fmt:literal $($arg:tt)*) => {{
$crate::MietteDiagnostic::new(format!($fmt $($arg)*))
}};
($($key:ident = $value:expr_2021,)+ $fmt:literal $($arg:tt)*) => {{
let mut diag = $crate::MietteDiagnostic::new(format!($fmt $($arg)*));
$($crate::__diagnostic_set_field!(diag, $key, $value);)*
diag
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __diagnostic_set_field {
($diag:ident, labels, $value:expr_2021) => {
$diag.labels = ::core::iter::IntoIterator::into_iter($value).collect();
};
($diag:ident, $key:ident, $value:expr_2021) => {
$diag.$key = Some($value.into());
};
}