summaryrefslogtreecommitdiff
path: root/crates/utils/src/lib.rs
blob: 248227a660f096909ebef1068c82874771a38d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#![no_std]

use core::fmt;

/// Creates an ad-hoc `Debug` instance.
pub fn debug(f: impl Fn(&mut fmt::Formatter) -> fmt::Result) -> impl fmt::Debug {
    struct Debug<F>(F);

    impl<F: Fn(&mut fmt::Formatter) -> fmt::Result> fmt::Debug for Debug<F> {
        fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
            (self.0)(fmt)
        }
    }

    Debug(f)
}