format-attr 0.2.1

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

// Test: Omit self. prefix - simple field names
#[derive(DisplayAttr, DebugAttr)]
#[fmt("Point({}, {})", x, y)]
struct Point {
    x: i32,
    y: i32,
}

// Test: Mix of with and without self.
#[derive(DisplayAttr, DebugAttr)]
#[fmt("Person: {} (age: {})", name, self.age)]
struct Person {
    name: String,
    age: u32,
}

// Test: With self. prefix for method calls
#[derive(DisplayAttr, DebugAttr)]
#[fmt("Name: {}", self.name.to_uppercase())]
struct Employee {
    name: String,
}

// Test: separate fmt_display and fmt_debug without self.
#[derive(DisplayAttr, DebugAttr)]
#[fmt_display("User: {}", name)]
#[fmt_debug("User {{ name: {}, age: {} }}", name, age)]
struct User {
    name: String,
    age: u32,
}

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

// Test: Multiple fields without self.
#[derive(DisplayAttr, DebugAttr)]
#[fmt("{}, {} @ {}", name, age, email)]
struct Contact {
    name: String,
    age: u32,
    email: String,
}

#[test]
fn test_point_without_self() {
    let p = Point { x: 10, y: 20 };
    assert_eq!(format!("{}", p), "Point(10, 20)");
    assert_eq!(format!("{:?}", p), "Point(10, 20)");
}

#[test]
fn test_person_mixed_self() {
    let p = Person {
        name: "Alice".to_string(),
        age: 30,
    };
    assert_eq!(format!("{}", p), "Person: Alice (age: 30)");
}

#[test]
fn test_employee_with_method_call() {
    let e = Employee {
        name: "bob".to_string(),
    };
    assert_eq!(format!("{}", e), "Name: BOB");
}

#[test]
fn test_user_separate_without_self() {
    let u = User {
        name: "Charlie".to_string(),
        age: 25,
    };
    assert_eq!(format!("{}", u), "User: Charlie");
    assert_eq!(format!("{:?}", u), "User { name: Charlie, age: 25 }");
}

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

#[test]
fn test_contact_multiple_fields() {
    let c = Contact {
        name: "David".to_string(),
        age: 35,
        email: "david@example.com".to_string(),
    };
    assert_eq!(format!("{}", c), "David, 35 @ david@example.com");
}