From 9730e785a885a4ab5fcc52ce705298654f82f9c2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 7 Feb 2022 14:19:13 +0100 Subject: Tidy up --- src/util/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/util/mod.rs') diff --git a/src/util/mod.rs b/src/util/mod.rs index 2f91100f..32ec8dc4 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -9,10 +9,30 @@ pub use mac_roman::decode_mac_roman; use std::cell::RefMut; use std::cmp::Ordering; +use std::fmt::{self, Debug, Formatter}; use std::ops::Range; use std::path::{Component, Path, PathBuf}; use std::sync::Arc; +/// Turn a closure into a struct implementing [`Debug`]. +pub fn debug(f: F) -> impl Debug +where + F: Fn(&mut Formatter) -> fmt::Result, +{ + struct Wrapper(F); + + impl Debug for Wrapper + where + F: Fn(&mut Formatter) -> fmt::Result, + { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.0(f) + } + } + + Wrapper(f) +} + /// Additional methods for strings. pub trait StrExt { /// The number of code units this string would use if it was encoded in -- cgit v1.2.3