-
Notifications
You must be signed in to change notification settings - Fork 21
/
macros.rs
70 lines (60 loc) · 1.97 KB
/
macros.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
//! General purpose macros.
/// Generate a lazy format!.
macro_rules! s {
($fmt:expr, $($arg:tt)+) => (|| format!($fmt, $($arg)+))
}
/// Call .into() on each element in a vec! initialization.
macro_rules! vec_into {
($($i:expr),*) => (vec![$($i.into()),*]);
}
/// Call .into() on each key and value in a hashmap! initialization.
macro_rules! indexmap_into {
($($key:expr => $value:expr),*) => (indexmap!{$($key.into() => $value.into()),*})
}
macro_rules! _header {
($verbosity:expr, $ctx:expr, $status:expr, $message:expr) => {
if $ctx.verbosity() >= $verbosity {
$ctx.log_header($status, $message);
}
};
}
macro_rules! _status {
($verbosity:expr, $color:expr, $ctx:expr, $status:expr, $message:expr) => {
if $ctx.verbosity() >= $verbosity {
$ctx.log_status($color, $status, $message);
}
};
}
/// Log a pretty header.
macro_rules! header {
($($arg:tt)*) => { _header!(crate::context::Verbosity::Normal, $($arg)*) };
}
macro_rules! header_v {
($($arg:tt)*) => { _header!(crate::context::Verbosity::Verbose, $($arg)*) };
}
/// Log a status.
macro_rules! status {
($($arg:tt)*) => { _status!(crate::context::Verbosity::Normal, crate::context::Color::Cyan, $($arg)*) }
}
macro_rules! status_v {
($($arg:tt)*) => { _status!(crate::context::Verbosity::Verbose, crate::context::Color::Cyan, $($arg)*) }
}
/// Log a warning.
macro_rules! warning {
($($arg:tt)*) => { _status!(crate::context::Verbosity::Normal, crate::context::Color::Yellow, $($arg)*) }
}
macro_rules! warning_v {
($($arg:tt)*) => { _status!(crate::context::Verbosity::Verbose, crate::context::Color::Yellow, $($arg)*) }
}
/// Log an error.
macro_rules! error {
($ctx:expr, $err:expr) => {
$ctx.log_error(crate::context::Color::Red, "error", $err);
};
}
/// Log an error but as a warning.
macro_rules! error_w {
($ctx:expr, $err:expr) => {
$ctx.log_error(crate::context::Color::Yellow, "warning", $err);
};
}