Crate debug_fn

Crate debug_fn 

Source
Expand description

This crate provides an adapter that allows you to turn any closure Fn(&mut Formatter<'_>) -> fmt::Result into a type that implements Display and Debug.

§Example

use core::fmt;
use core::fmt::Formatter;
use debug_fn::debug_fn;

fn hello(f: &mut Formatter<'_>, user_id: Option<u64>) -> fmt::Result {
    if let Some(user_id) = user_id {
        write!(f, "user number {}", user_id)
    } else {
        write!(f, "anonymous user")
    }
}

assert_eq!(format!("Hello {}", debug_fn(|f| hello(f, Some(1234)))), "Hello user number 1234");
assert_eq!(format!("Hello {}", debug_fn(|f| hello(f, None))), "Hello anonymous user");

Structs§

DebugFn
A type that implements Display and Debug.

Functions§

debug_fn
Creates a type that implements Display and Debug from a closure.