In our last article, we created our first Rust program, learned how to compile and build it with rustc. We also explored how to manage projects effectively using Rust's build system, Cargo. Today, we'll dive into the various ways Rust's standard library helps us with printing and logging. Understanding how to output information is a fundamental step when learning any new language – let's jump right in!
You can find all the code examples we will discuss in the Rust repository on the inpyjama GitHub page: https://github.com/inpyjama/rust/. To run the demo, navigate to the "day3" folder and execute cargo run.
The Print Macros
Let's start with the foundational building blocks of printing in Rust: println! and print!. The println! macro inserts a newline character after printing your message, ensuring subsequent output appears on a new line. Conversely, the print! macro displays your message without any additional newline characters.
Don't Miss an Update!
Helping you navigate the Embedded Systems career with ease! Technical posts, newsletters, special offers, and more.