formati
Enhanced Rust formatting macros with dotted notation and expression interpolation
formati is a collection of procedural macros that extend Rust's standard formatting facilities in two key ways:
- Automatic handling of dotted notation for struct fields, tuple elements, and method calls
- Deduplication of identical expressions that appear multiple times in the format string
Features
- Dotted notation: Access struct fields and tuple elements with natural dot notation
- Expression deduplication: Automatically prevents repeated evaluation of the same expressions
- Full format specifier support: Works with all standard format specifiers (
{:?},{:.2}, etc.) - Tracing integration: Enhanced versions of common tracing macros
- Standard library wrappers: Drop-in replacements for
print!andprintln!
Installation
Add formati to your Cargo.toml:
[]
= "0.1"
Usage
Basic Formatting with formati!
use formati;
Format Specifiers
use formati;
Tracing Integration
formati-style versions of tracing macros that support dotted notation:
use ; // use in place of tracing::{debug, error, info, trace}
use FmtSubscriber;
Print and Println Wrappers
use ;
How It Works
The formati crate processes format strings at compile time to:
- Find placeholders with dotted notation (
{example.field}) - Extract these expressions and deduplicate them
- Replace them with indexed placeholders
- Add the extracted expressions as arguments to the underlying format macro
This approach avoids evaluating the same expression multiple times and makes your format strings more readable.
Expansion Demonstration
let point = Point ;
let info = formati!;
The format! macro would expand to:
must_use
License
This project is licensed under the MIT License.