When using Serde's default derive for complex Rust enums, the resulting serialized output is verbose and exposes implementation details, making config files and API payloads hard for humans to read or write. A better approach is to implement `Display` and `FromStr` traits to define a clean string representation, then wire those into Serde's `Serialize`/`Deserialize` traits manually or via `serde_with`'s `SerializeDisplay` and `DeserializeFromStr` derive attributes. The post walks through a real-world keybinding config example using the `bacon` tool, shows how to use `lazy-regex`'s `regex_switch!` macro for lenient parsing, and emphasizes writing round-trip tests. The technique applies equally to REST/JSON APIs where human-readable values matter.
Table of contents
WhyChoose a formatStart with FromStr/DisplayAdd Serde implementationsNot just configurationSort: