1
0
Fork 0
forked from wry/wry
wry/src/utils/debug_fn.rs
2022-04-05 21:08:07 +02:00

30 lines
571 B
Rust

use std::fmt::{Debug, Display, Formatter};
pub fn debug_fn<F>(f: F) -> Printable<F>
where
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
{
Printable { f }
}
pub struct Printable<F> {
f: F,
}
impl<F> Debug for Printable<F>
where
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
(self.f)(f)
}
}
impl<F> Display for Printable<F>
where
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
(self.f)(f)
}
}