Rust print: Difference between revisions
From wikinotes
No edit summary |
|||
Line 17: | Line 17: | ||
let b = "B"; | let b = "B"; | ||
println!("{a}--{b}"); // string interpolation | println!("{a}--{b}"); // string interpolation | ||
println!("hello, {name}", name="will"); // keyword assignment | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- String Interpolation --> | </blockquote><!-- String Interpolation --> |
Revision as of 14:33, 7 February 2023
https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html
println
Printing
println!("abc");String Interpolation
let a = "A"; let b = "B"; println!("{a}--{b}"); // string interpolation println!("hello, {name}", name="will"); // keyword assignmentFormatting
println!("Hello, {}", "alex"); println!("{0}, {0}, see {1}?", "alex", "movie"); println!("{person}, see {thing}?", person="alex", thing="movie");Type Formatting
// formatting println!("{:>4}", 2) // " 2" right align println!("{:0>4}", 2) // "0002" right align, padded w/ zeros println!("{var:>4}", var="boo") // " boo" right align // type formatting println!("{:X}", 1234) // "4D2" hex println!("{:o}", 1234) // "2322" octal