debug-fn 1.0.0

A function adapter that implements Display and Debug
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 3 items with examples
  • Size
  • Source code size: 6.79 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 785.4 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • mahkoh/debug-fn
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mahkoh

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.