error_kind/macros/err.rs
1// =============================================================================
2// MACROS
3// =============================================================================
4
5// -----------------------------------------------------------------------------
6cfg_select! {
7 feature = "alloc" => {
8 #[macro_export]
9 #[doc = include_str!("err.md")]
10 macro_rules! err {
11 ($error_kind:expr $(,)?) => {
12 $crate::TrivialError::new($error_kind.into())
13 };
14 ($error_kind:expr, $($arg:tt)*) => {
15 $crate::TrivialError::with_description(
16 $error_kind.into(),
17 $crate::__private::format!($($arg)*),
18 )
19 };
20 }
21 },
22 _ => {
23 #[macro_export]
24 #[doc = include_str!("err.md")]
25 macro_rules! err {
26 ($error_kind:expr $(,)?) => {
27 $crate::TrivialError::new($error_kind.into())
28 };
29 ($error_kind:expr, $($arg:tt)*) => {{
30 let _ = $crate::__private::format_args!($($arg)*);
31 $crate::TrivialError::new($error_kind.into())
32 }};
33 }
34 },
35}
36
37/// Wraps a provided error kind and optional description in an error.
38///
39/// This is equivalent to typing `Err(err!(...))`. See the [`err!`] macro for
40/// more information.
41///
42/// > **NOTE:** The `Err!` macro does not conflict with the `Err` result
43/// > variant. You can mix your usage of these two items if you want to.
44/// >
45/// > If you don't like using this macro, that's totally fine as well. :)
46#[macro_export]
47macro_rules! Err {
48 ($($tt:tt)*) => { Err($crate::err!($($tt)*)) };
49}