macro_rules! cmp_assert_str_docs {
($assert_str:literal, $std_assert:literal) => {
concat!(
"[**examples below**](#examples)",
"\n\n",
"This macro is only evaluated at compile-time if used in a context that requires it ",
"(eg: in the expression assigned to a `const _: () = `)",
"\n\n",
"If you only need to use this at runtime, consider using [`",
$std_assert,
"`] instead.\n",
"\n\n",
"# Arguments\n",
"\n",
"The `$left` and `$right` arguments can each be (independently of the other):\n",
"- `&str`\n",
"- `&&str`\n",
"- `TStr<_>`\n",
"- `&TStr<_>`\n",
"\n\n",
"(the references can be of any lifetime)\n",
"\n\n",
"The rest of the arguments are formatting arguments for the panic message",
" for when the assertion fails, ",
"[described in the section below](#formatting)\n",
"\n\n",
"# Formatting ",
"\n\n",
"This uses the same syntax for formatting arguments as ",
"[`const_panic::concat_panic`](macro@const_panic::concat_panic).",
"\n\n",
"By default, this only supports primitive types as formatting arguments, ",
"to format arrays or custom types you must enable ",
r#"`const_panic`'s `"non_basic"` feature."#,
"\n\n",
"To print user-defined types, ",
"they must implement the [`const_panic::fmt::PanicFmt`]",
" trait as described in its docs.\n",
"\n\n",
"# Features\n",
"\n",
"This macro requires the (default-enabled) `\"const_panic\"` crate feature",
" to be enabled.\n",
"\n\n",
"[`TStr`]: crate::TStr",
"\n",
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __cmp_assert_inner {
($left:expr, $right:expr, $is_equal:ident, $operator:literal, $($($fmt:tt)+)?) => (
match (&$left, &$right) {
(left, right) => {
let left = $crate::strlike::as_str!(left);
let right = $crate::strlike::as_str!(right);
if let $is_equal = $crate::utils::str_eq(left, right) {
$crate::__p::concat_panic!{
display: $crate::__p::concat!(
"\nassertion failed: LEFT ",
$operator,
" RIGHT\n left: `",
),
left,
"`\nright: `",
right,
"`\n",
$( ": ", $($fmt)+)?
}
}
}
}
)
}
#[doc = cmp_assert_str_docs!("assert_str_eq", "assert_eq")]
#[macro_export]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "const_panic")))]
macro_rules! assert_str_eq {
($left:expr, $right:expr $(, $($fmt:tt)* )? ) => (
$crate::__cmp_assert_inner!{$left, $right, false, "==", $($($fmt)*)?}
);
}
#[doc = cmp_assert_str_docs!("assert_str_ne", "assert_ne")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "const_panic")))]
#[macro_export]
macro_rules! assert_str_ne {
($left:expr, $right:expr $(, $($fmt:tt)* )? ) => (
$crate::__cmp_assert_inner!{$left, $right, true, "!=", $($($fmt)*)?}
);
}