2 stable releases

1.0.1 Nov 11, 2023

#65 in #better

Download history 22/week @ 2024-07-01 12/week @ 2024-07-15 16/week @ 2024-07-22 21/week @ 2024-07-29 6/week @ 2024-08-05 45/week @ 2024-08-12 14/week @ 2024-08-19 30/week @ 2024-08-26 26/week @ 2024-09-02 50/week @ 2024-09-09 15/week @ 2024-09-16 12/week @ 2024-09-23 14/week @ 2024-09-30 29/week @ 2024-10-07 23/week @ 2024-10-14

79 downloads per month
Used in txtx-core

MIT license

20KB
352 lines

BetterDebug: Saner and cooler Debug macro for rust

This crate aims to provide a nice, and actually sane implementation of the Debug trait.

This macro provides the following features, compared to the standard library Debug's macro:

  • Mark a field as secret (this will hide its contents when fmt::Debug is called upon it)
  • Ability to use a custom formatter function for each struct field. Furthermore, you have the ability to return a None in your custom formatter if you want to skip printing that specific field, or if you want to use the default formatter. All of this can be configured via a macro attribute.
  • Ability to prevent fields from being formatted.
  • Ability to rename any given field to whatever you want.

Examples

Note: You can find more examples here.

 use better_debug::BetterDebug;

 fn foo(foo: &Foo) -> Option<&'static str> {
     if foo.bar.len() < 5 {
         return Some("lorem ipsum");
     }
     None
 }

 #[derive(BetterDebug)]
 struct Foo {
     #[better_debug(cust_formatter = "foo")]
     bar: String,
     baz: String,
}

License

MIT

Dependencies

~0.6–1.1MB
~24K SLoC