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
#[macro_export]
macro_rules! format_smartstring {
    ($($arg:tt)*) => {{
        use smartstring::alias::String as SmartString;
        use std::fmt::Write;

        let mut string = SmartString::new();
        write!(string, $($arg)*).unwrap();
        string
    }}
}

#[macro_export]
macro_rules! format_list_container {
    ($e:expr, $start:tt, $end:tt) => {{
        use std::fmt::Write;
        let mut out = String::new();
        out.push($start);
        let mut iter = $e.into_iter();
        let mut next = iter.next();

        loop {
            if let Some(val) = next {
                write!(out, "{val}").unwrap();
            };
            next = iter.next();
            if next.is_some() {
                out.push_str(", ")
            } else {
                break;
            }
        }
        out.push($end);
        out
    };};
}

#[macro_export]
macro_rules! format_list {
    ($e:expr) => {{
        use polars_utils::format_list_container;
        format_list_container!($e, '[', ']')
    };};
}

#[macro_export]
macro_rules! format_tuple {
    ($e:expr) => {{
        use polars_utils::format_list_container;
        format_list_container!($e, '(', ')')
    };};
}