enigma_3d/logging/
format.rs1#[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 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), _ => write!(result, "{}", format_spec), }.unwrap();
28
29 result.push_str(&rest[1..]); } else {
31 result.push('{');
32 result.push_str(part);
33 }
34 }
35 )*
36
37 for part in fmt_parts {
39 result.push('{');
40 result.push_str(part);
41 }
42
43 result
44 }};
45}