DaleSchool

Meeting Rust

Beginner10min

Learning Objectives

  • Describe what Rust is in one sentence
  • Run code in the Rust Playground
  • Print text using the println! macro

Working Code

Try running this code in the Rust Playground!

fn main() {
    println!("Hello, DaleSchool!");
    println!("Welcome to the world of Rust 🎉");
}

Try It Yourself

Change the text inside println! to your own name. What happens?

"Why?" — What Kind of Language Is Rust?

Rust is a fast and safe programming language. Every Rust program starts inside fn main(). For now, just remember that you write your code inside this block.

println! is a command that prints text to the screen. You'll notice the ! at the end — we'll get to that later.

Deep Dive

What's the exclamation mark in println! for?

In Rust, anything with a ! at the end of its name is a macro. It's a bit different from a regular function, but for now you can think of it as a "special function." We'll cover macros in detail later on.

What happens if you leave out the ! after println?

fn main() {
    println("Oops, forgot the bang!");
}

The compiler shows an error like this:

error[E0423]: expected function, found macro `println`

Add the ! back and it works again. Don't be afraid of compiler errors — the error messages tell you how to fix things!

  1. Write a program that prints a 3-line self-introduction using println!.
  2. What does an empty println!() produce? Try running it and find out.

Q1. What is the entry point of a Rust program?

  • A) start()
  • B) run()
  • C) fn main()
  • D) begin()