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
71
72
73
use std::fmt;

pub(crate) type BuildHasher = fxhash::FxBuildHasher;
pub(crate) type HashMap<K, V, B = BuildHasher> = std::collections::HashMap<K, V, B>;
pub(crate) type HashSet<K, B = BuildHasher> = std::collections::HashSet<K, B>;
pub(crate) type Instant = quanta::Instant;


macro_rules! function_name {
    ($lvl: literal) => {{
        fn __f__() {}
        fn type_name_of<T>(_: T) -> &'static str {
            std::any::type_name::<T>()
        }
        type_name_of(__f__)
            .split("::")
            .skip($lvl)
            .filter(|&name| name != "__f__")
            .collect::<Vec<_>>()
            .join("::")

            //.find(|&part| part!= "f" && part != "{{closure}}")
            //.expect("function name")
    }};
}
pub(crate) use function_name;

macro_rules! trace_fn {
    () => {{
        use std::fmt::Write;
        let mut buff = String::new();
        write!(buff, "{}", crate::utils::function_name!(2)).unwrap();
        log::trace!("{}", buff);
    }};
    ($($tt:tt)+) => {{
        use std::fmt::Write;
        let mut buff = String::new();
        write!(buff, "{}: ", crate::utils::function_name!(2)).unwrap();
        write!(buff, $($tt)*).unwrap();
        log::trace!("{}", buff);
    }}
}
pub(crate) use trace_fn;


//pub trait Pow<Rhs = Self> {
//    type Output;
//    fn pow(self, rhs: Rhs) -> Self::Output;
//}

pub(crate) fn fmt_iter<E: fmt::Debug, F>(
    symbols: [&str; 3],
    mut it: impl Iterator<Item = E>,
    fmt_e: F,
    f: &mut fmt::Formatter<'_>,
) -> fmt::Result
where
    F: Fn(&E, &mut fmt::Formatter<'_>) -> fmt::Result,
{
    let start = symbols[0];
    let delimiter = symbols[1];
    let end = symbols[2];
    write!(f, "{start}")?;
    if let Some(first) = it.next() {
        fmt_e(&first, f)?;
    }
    for e in it {
        write!(f, "{delimiter}")?;
        fmt_e(&e, f)?;
    }
    write!(f, "{end}")?;
    Ok(())
}