summaryrefslogtreecommitdiff
path: root/src/util/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/mod.rs')
-rw-r--r--src/util/mod.rs20
1 files changed, 20 insertions, 0 deletions
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: F) -> impl Debug
+where
+ F: Fn(&mut Formatter) -> fmt::Result,
+{
+ struct Wrapper<F>(F);
+
+ impl<F> Debug for Wrapper<F>
+ 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