From 1867170d185c3480542773a74876175e341b91eb Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Sun, 1 Sep 2024 18:32:38 -0500 Subject: Simplify debug printing of the buddy allocator. --- crates/utils/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 crates/utils/src/lib.rs (limited to 'crates/utils/src/lib.rs') 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); + + impl fmt::Result> fmt::Debug for Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + (self.0)(fmt) + } + } + + Debug(f) +} -- cgit v1.2.3