vortex_utils/debug_with.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Utilities for implementing `Debug` via a closure.
5//!
6//! This provides a stable alternative to the `debug_closures` feature: <https://github.com/rust-lang/rust/issues/117729>.
7
8use std::fmt;
9
10/// A wrapper that implements `Debug` via a closure.
11pub struct DebugWith<F>(pub F)
12where
13 F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result;
14
15impl<F> fmt::Debug for DebugWith<F>
16where
17 F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
18{
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 (self.0)(f)
21 }
22}