bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Rust/Rust Tutorial
Rust•Rust Tutorial

Rust Syntax

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Rust Syntax?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___!("Hello World!");
3Order

Put the learning moves in the order that makes the concept easiest to apply.

A macro is like a function, but with an exclamation mark ( !
Line 1: fn main() is something that always appears at the beginning of every Rust program.
You have already seen the following code a couple of times in the first chapters.

Syntax

You have already seen the following code a couple of times in the first chapters. Let's break it down to understand it better:

Example

fn main() {
  println!("Hello World!");
}

Example explained

Line 1: fn main() is something that always appears at the beginning of every Rust program. main() is called a function , and any code inside its curly brackets {} will be executed.

Line 2: println!() is a macro , used to output/print text to the screen. In our example it will output "Hello World!". To end the code, you must remember a semicolon ( ; ).

What is a macro?

A macro is like a function, but with an exclamation mark ( ! ) after it. Don't worry about the terminology for now. For now, just know that macros are similar to functions (they execute things), but they do not always follow the same rules as functions. You will learn more about macros later.

Good to know: The Rust compiler ignores white spaces.

The code above could also been written as: fn main(){println!("Hello World!");}

However , multiple lines and indentation makes the code more readable.

Previous

Rust Get Started

Next

Rust Output (Print Text)