format-attr
document: https://docs.rs/format-attr
A Rust proc-macro crate that provides custom derive macros for implementing Display and Debug traits with custom format strings.
Features
DisplayAttr- Derivestd::fmt::Displaywith a custom format stringDebugAttr- Derivestd::fmt::Debugwith a custom format stringDisplayAsDebug- ImplementDisplayby delegating to the existingDebugimplementation- Support for separate format strings via
#[fmt_display(...)]and#[fmt_debug(...)] - Fallback to shared
#[fmt(...)]attribute
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Example
use ;
let p = Point ;
assert_eq!;
assert_eq!;
Separate Format Strings
Use #[fmt_display(...)] and #[fmt_debug(...)] for different output:
use ;
let u = User ;
assert_eq!;
assert_eq!;
DisplayAsDebug
When you want Display to use the same output as Debug:
use DisplayAsDebug;
;
let v = Value;
assert_eq!;
assert_eq!;
Attribute Priority
| Derive Macro | Priority 1 | Priority 2 (fallback) |
|---|---|---|
DisplayAttr |
#[fmt_display(...)] |
#[fmt(...)] |
DebugAttr |
#[fmt_debug(...)] |
#[fmt(...)] |
License
MIT