Concept Flow - Formatting output
Start
Prepare data
Choose format string
Apply formatting
Print or store output
End
This flow shows how Rust takes data, applies a format string, and produces formatted output.
fn main() {
let name = "Alice";
let age = 30;
println!("Name: {}, Age: {}", name, age);
}| Step | Action | Format String | Values | Result |
|---|---|---|---|---|
| 1 | Start main function | |||
| 2 | Assign variable name | name = "Alice" | ||
| 3 | Assign variable age | age = 30 | ||
| 4 | Call println! macro | Name: {}, Age: {} | name="Alice", age=30 | Prints: Name: Alice, Age: 30 |
| 5 | End main function |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| name | uninitialized | "Alice" | "Alice" | "Alice" |
| age | uninitialized | uninitialized | 30 | 30 |
Rust formatting output uses curly braces {} as placeholders.
Use println!("text {}, {}", val1, val2) to print formatted text.
The number of placeholders must match the number of values.
Rust checks this at compile time to avoid errors.
This helps create readable and dynamic output.