diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-09-01 18:32:38 -0500 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-09-01 18:32:38 -0500 |
commit | 1867170d185c3480542773a74876175e341b91eb (patch) | |
tree | 64e5f943a1d3d09d875309077e6ee4bf86aff340 /crates/utils/src | |
parent | 20c90c707d5f6870bd7d545f06f669cd839b6348 (diff) |
Simplify debug printing of the buddy allocator.
Diffstat (limited to 'crates/utils/src')
-rw-r--r-- | crates/utils/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs new file mode 100644 index 0000000..248227a --- /dev/null +++ b/crates/utils/src/lib.rs @@ -0,0 +1,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) +} |