Lesson 2 - Macros vs Functions

Опубликовано: 29 Май 2026
на канале: LateNiteLecturer
44
4

Learn how Rust macros work by typing the code yourself.

In this lesson we take a closer look at something you already used in the previous video: `println!`. You may have noticed the exclamation mark at the end. That symbol tells Rust that `println!` is not a normal function, but a macro.

In this lesson we go a step further and create our own macro. This will help you understand how Rust can generate code automatically in other parts of our code by copying our macro content.

This course focuses on learning Rust by doing, so you should type the program yourself and run it as you follow along.

In this video you will learn:

• what a Rust macro is
• why macros use the `!` symbol
• how to create a macro using `macro_rules!`
• how to call a macro in your program

At the end of the lesson you will have written your own macro that prints a welcome message to the terminal.

For this course we assume you already have Rust and Cargo installed and that you know how to create and run a Cargo project.

If you cannot run Rust locally, you can also try the code in the Rust online playground:
[https://play.rust-lang.org/](https://play.rust-lang.org/)

This lesson is part of a beginner-friendly Rust series where we learn the language by building lots of small programs.

Subscribe for more Rust programming lessons.

#Rust #LearnRust #RustProgramming #CodingForBeginners #Programming