How do I make the fill padding in std::format dynamic?

Viewed 422

To create a format output and pad your output with n you can do something like this in rust:

fn main() {
    let title = " Title ";
    println!("┌{:─^11}┐", title);
}

That will print:

┌── Title ──┐

So the str is padded (centered via ^) on both sides with - within the space of 11 characters.

How can I make this width dynamic though? Via a variable.

1 Answers
Related