-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.rs
83 lines (81 loc) Β· 1.66 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/// π§ Β» create string
/// --
///
/// create a new `String` from a string literal or a string expression -
/// this macro is equivalent to `String::from(<args>)`.
///
/// ### Example
/// ```rust
/// use lool::s;
/// let s: String = s!("hello world");
/// ```
#[macro_export]
macro_rules! s {
($s:expr) => {
String::from($s)
};
}
/// π§ Β» fail macro
/// --
///
/// this macro is equivalent to `Err(eyre!(<args>))`.
///
/// same as `bail!` but without the explicit return
///
/// ### Example
///
/// ```should_panic
/// use lool::fail;
/// use eyre::Result;
/// # use eyre::{set_hook, DefaultHandler};
/// # fn setup_eyre() {
/// # let _ = set_hook(Box::new(DefaultHandler::default_with));
/// # }
///
/// fn main() -> Result<()> {
/// # setup_eyre();
/// fail!("permission denied")
/// }
/// ```
#[macro_export]
macro_rules! fail {
($msg:literal $(,)?) => {
Err(eyre::eyre!($msg))
};
($err:expr $(,)?) => {
Err(eyre::eyre!($err))
};
($fmt:expr, $($arg:tt)*) => {
Err(eyre::eyre!($fmt, $($arg)*))
};
}
/// π§ Β» fail macro
/// --
///
/// this macro is equivalent to `Err(eyre!(<args>))`.
///
/// same as `bail!` but without the explicit return
///
/// this is an alias for `fail!`
///
/// ### Example
///
/// ```should_panic
/// use lool::f;
/// use eyre::Result;
/// # use eyre::{set_hook, DefaultHandler};
/// # fn setup_eyre() {
/// # let _ = set_hook(Box::new(DefaultHandler::default_with));
/// # }
///
/// fn main() -> Result<()> {
/// # setup_eyre();
/// f!("permission denied")
/// }
/// ```
#[macro_export]
macro_rules! f {
($($tokens:tt)*) => {
lool::fail!($($tokens)*)
};
}