Skip to content

bits-of-rust/episode-003

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

episode-003

Where we print a formatted message

Setup

The following needs to be prepared

  • A cargo created Rust named printing
  • An editor with the project open

Script

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

Releases

No releases published

Packages

No packages published

Languages