Where we print a formatted message
The following needs to be prepared
- A
cargocreated Rust namedprinting - An editor with the project open
Having setup our Rust environment, it is time we explore the language.
I have used cargo to create a new project. Lets run it to see we are in a working system. I setup the editor to execute cargo run on Command-B. We can see the output below.
The println! macro has a trick up its sleave. Change the expression to
println!("Hello, {}!", "world");When we run it we see that println! can accept an argument. The argument "world" is replaced with the placeholder {}, sometimes called a mustache pair.
println! can accept multiple arguments. For example
println!("{}, {}!", "Hello", "world");works just as well.
And there you have it, we printed a formatted message