enigma_3d/logging/
format.rs

1#[macro_export]
2macro_rules! smart_format {
3    ($fmt:expr) => {{
4        $fmt.to_string()
5    }};
6    ($fmt:expr, $($arg:expr),*) => {{
7        use std::fmt::Write;
8        let mut result = String::new();
9        let mut fmt_parts = $fmt.split('{');
10
11        // Handle the first part (before any format specifiers)
12        if let Some(part) = fmt_parts.next() {
13            result.push_str(part);
14        }
15
16        $(
17            if let Some(part) = fmt_parts.next() {
18                if let Some(end_brace) = part.find('}') {
19                    let (format_spec, rest) = part.split_at(end_brace);
20                    let format_spec = format_spec.trim();
21
22                    match format_spec {
23                        ":?" => write!(result, "{:?}", $arg),
24                        ":#?" => write!(result, "{:#?}", $arg),
25                        "" => write!(result, "{:?}", $arg),  // Use debug formatting by default
26                        _ => write!(result, "{}", format_spec),  // For unsupported format specifiers, just write them as-is
27                    }.unwrap();
28
29                    result.push_str(&rest[1..]);  // Skip the closing brace
30                } else {
31                    result.push('{');
32                    result.push_str(part);
33                }
34            }
35        )*
36
37        // Handle any remaining parts of the format string
38        for part in fmt_parts {
39            result.push('{');
40            result.push_str(part);
41        }
42
43        result
44    }};
45}