format-attr 0.2.1

a custom derive to implement Debug/Display easy
Documentation
use format_attr::{DebugAttr, DisplayAttr};

#[derive(DisplayAttr, DebugAttr)]
#[fmt("Wrapper({})", self.value)]
struct Wrapper<T: std::fmt::Display> {
    value: T,
}

#[derive(DisplayAttr, DebugAttr)]
#[fmt("Pair({}, {})", self.first, self.second)]
struct Pair<T: std::fmt::Display, U: std::fmt::Display> {
    first: T,
    second: U,
}

#[test]
fn test_wrapper_i32() {
    let w = Wrapper { value: 42 };
    assert_eq!(format!("{}", w), "Wrapper(42)");
    assert_eq!(format!("{:?}", w), "Wrapper(42)");
}

#[test]
fn test_wrapper_string() {
    let w = Wrapper {
        value: "hello".to_string(),
    };
    assert_eq!(format!("{}", w), "Wrapper(hello)");
}

#[test]
fn test_pair_mixed() {
    let p = Pair {
        first: 10,
        second: "world",
    };
    assert_eq!(format!("{}", p), "Pair(10, world)");
}