Skip to main content

ankurah_core/util/
mod.rs

1pub mod cast;
2pub mod expand_states;
3pub mod iterable;
4pub mod ivec;
5pub mod ready_chunks;
6pub mod safemap;
7pub mod safeset;
8pub use iterable::Iterable;
9pub use ivec::IVec;
10
11/// Formats an action log with consistent styling.
12/// First argument is always a "thing" that performed the action (in bold blue)
13/// Second argument is the action name (in green)
14/// Remaining arguments are formatted as additional context (dimmed)
15#[macro_export]
16macro_rules! action_info {
17    // Thing + action
18    ($thing:expr, $action:expr) => {
19        tracing::info!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m", $thing, $action)
20    };
21    // Thing + action + args
22    ($thing:expr, $action:expr, $($arg:expr),+) => {
23        tracing::info!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m \x1b[2m{}\x1b[0m", $thing, $action, format!("{}", format_args!($($arg),+)))
24    };
25}
26
27#[macro_export]
28macro_rules! action_debug {
29    // Thing + action
30    ($thing:expr, $action:expr) => {
31        tracing::debug!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m", $thing, $action)
32    };
33    // Thing + action + args
34    ($thing:expr, $action:expr, $($arg:expr),+) => {
35        tracing::debug!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m \x1b[2m{}\x1b[0m", $thing, $action, format!("{}", format_args!($($arg),+)))
36    };
37}
38
39#[macro_export]
40macro_rules! action_warn {
41    // Thing + action
42    ($thing:expr, $action:expr) => {
43        tracing::warn!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m", $thing, $action)
44    };
45    // Thing + action + args
46    ($thing:expr, $action:expr, $($arg:expr),+) => {
47        tracing::warn!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m \x1b[2m{}\x1b[0m", $thing, $action, format!("{}", format_args!($($arg),+)))
48    };
49}
50
51#[macro_export]
52macro_rules! action_error {
53    // Thing + action
54    ($thing:expr, $action:expr) => {
55        tracing::error!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m", $thing, $action)
56    };
57    // Thing + action + args
58    ($thing:expr, $action:expr, $($arg:expr),+) => {
59        tracing::error!("\x1b[1;34m{}\x1b[0m → \x1b[32m{}\x1b[0m \x1b[2m{}\x1b[0m", $thing, $action, format!("{}", format_args!($($arg),+)))
60    };
61}
62
63/// Formats a notice log with consistent styling.
64/// The message is displayed in bold yellow to make it stand out.
65#[macro_export]
66macro_rules! notice_info {
67    ($($arg:tt)*) => {
68        tracing::info!("\x1b[1;33m{}\x1b[0m", format!($($arg)*))
69    };
70}