From 4504870c29bc46e72d53fa1a1557392bf41b9524 Mon Sep 17 00:00:00 2001 From: Taufik Rama Date: Sat, 5 Feb 2022 09:48:29 +0700 Subject: [PATCH] Added new Rust 1.58 direct format args --- src/hello/print.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hello/print.md b/src/hello/print.md index 7575024060..c25df9ba48 100644 --- a/src/hello/print.md +++ b/src/hello/print.md @@ -54,6 +54,13 @@ fn main() { // handling. This will not work. println!("This struct `{}` won't print...", Structure(3)); // FIXME ^ Comment out this line. + + // For Rust 1.58 and above, you can directly capture the argument from + // surrounding variable. Just like the above, this will output + // " 1". 5 white spaces and a "1". + let number: f64 = 1.0; + let width: usize = 6; + println!("{number:>width$}"); } ```