Pad a string in Rust using the format! macro with alignment specifiers like < for left and > for right padding.
Use the format! macro with the {0:<width} syntax to left-pad or {0:>width} to right-pad a string. This creates a new string with the original text aligned and filled with spaces to the specified width.
let text = "hello";
let padded_left = format!("{0:<10}", text); // "hello "
let padded_right = format!("{0:>10}", text); // " hello"
Padding adds extra spaces to the beginning or end of a text string to make it a specific length. You use this when you need columns of text to line up neatly in a report or log file. Think of it like adding blank space to a sticky note so it fits perfectly into a designated slot.