debug-fn

Crates.iodebug-fn
lib.rsdebug-fn
version1.0.0
sourcesrc
created_at2024-12-14 09:50:38.166989+00
updated_at2024-12-14 09:50:38.166989+00
descriptionA function adapter that implements Display and Debug
homepage
repositoryhttps://github.com/mahkoh/debug-fn
max_upload_size
id1483024
size7,132
(mahkoh)

documentation

README

debug-fn

crates.io docs.rs

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");

License

This project is licensed under either of

  • Apache License, Version 2.0
  • MIT License

at your option.

Commit count: 0

cargo fmt