Rust print: Difference between revisions
From wikinotes
(Created page with " = println = <blockquote> == String Interpolation == <blockquote> <syntaxhighlight lang="rust"> println!("abc"); </syntaxhighlight> </blockquote><!-- String Interpolation --> == Formatting == <blockquote> <syntaxhighlight lang="rust"> println!("Hello, {}", "alex"); println!("{0}, {0}, see {1}?", "alex", "movie"); println!("{person}, see {thing}?", person="alex", thing="movie"); </syntaxhighlight> </blockquote><!-- Formatting --> == Type Formatting == <blockquote> <synt...") |
|||
Line 2: | Line 2: | ||
= println = | = println = | ||
<blockquote> | <blockquote> | ||
== Printing == | |||
<blockquote> | |||
<syntaxhighlight lang="rust"> | |||
println!("abc"); | |||
</syntaxhighlight> | |||
</blockquote><!-- String Interpolation --> | |||
== String Interpolation == | == String Interpolation == | ||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang="rust"> | <syntaxhighlight lang="rust"> | ||
println!(" | let a = "A"; | ||
let b = "B"; | |||
println!("{a}--{b}"); // string interpolation | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- String Interpolation --> | </blockquote><!-- String Interpolation --> |
Revision as of 22:24, 6 February 2023
println
Printing
println!("abc");String Interpolation
let a = "A"; let b = "B"; println!("{a}--{b}"); // string interpolationFormatting
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