Display
The Display derive macro implements std::fmt::Display for your structs. It supports multiple output formats, custom format strings, JSON serialization, and colored terminal output.
Default Format
Without any attributes, Display produces a struct-literal style output:
use moxy::Display;
#[derive(Display)]
struct User {
name: String,
email: String,
}
let user = User {
name: "John".into(),
email: "john@example.com".into(),
};
assert_eq!(format!("{user}"), "User { name: John, email: john@example.com }");
Attribute Syntax
Display behavior is controlled through #[moxy(display(...))] attributes at the struct level and field level:
use moxy::Display;
#[derive(Display)]
#[moxy(display(debug, pretty))] // struct-level: format + modifiers
struct User {
name: String,
#[moxy(display(skip))] // field-level: skip this field
password: String,
}
Multiple #[moxy(...)] attributes on the same item are merged, so these two forms are equivalent:
#[moxy(display(debug, pretty))]
// same as:
#[moxy(display(debug))]
#[moxy(display(pretty))]
Tip
Splitting attributes across multiple lines is useful when mixing format flags with field-level overrides — each concern can live on its own
#[moxy(...)]line.
What’s Next
- Formats — debug, compact, keyvalue, map
- Pretty Printing — multi-line output
- Custom Format Strings — template syntax with expressions
- JSON — JSON serialization
- Color — ANSI colored output with themes
- Fields — skip and alias fields
- Struct Types — named, tuple, and unit structs