Compile and run a Rust program from scratch

Pascal Precht
InstructorPascal Precht
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

In this lesson we’ll create our first “Hello World” Rust program from scratch and will learn how to compile it using rustc.

Instructor: [00:00] Start by creating a file main.rs and create a function main() using the fn keywords. This is the function that will be run when we execute our program. To output "Hello, World" we use println!, or print line, which takes a string. We give it "Hello, World." Then we save the file.

[00:25] Next, we compile the program using the rustc compiler. Once that is done, we'll see that there is a new file called main, which can be executed straight from the command line.

Michele Nasti
Michele Nasti
~ 5 years ago

Why println! function has the exclamation mark at the end? Is this special, a convention, or it's just part of the function name?

Roberto Zaniboni
Roberto Zaniboni
~ 5 years ago

It is a macro. https://doc.rust-lang.org/rust-by-example/macros.html

Pascal Precht
Pascal Prechtinstructor
~ 5 years ago

Hi Michele!

As Roberto pointed out, println! is a macro and not just a function. In this course however, I didn't want to go into macros to keep things as simple as possible. So from that perspective, all you needed to know was that println!() is a function for now :)

There will be a course on macros as well, once I've mastered them! :D

J. Matthew
J. Matthew
~ 5 years ago

Why println! function has the exclamation mark at the end? Is this special, a convention, or it's just part of the function name?

Thanks for asking this; I was wondering the same thing!

Macros sound interesting, based on a quick look at the link @Roberto provided. I look forward to learning more about them (but I appreciate that complexity not being introduced in this video).

Pascal Precht
Pascal Prechtinstructor
~ 5 years ago

Macros are extremely powerful but not easy to master. I've read into them a while ago and decided to put them aside for now. Glad to hear there's interest in a dedicated course on that! :)

Markdown supported.
Become a member to join the discussionEnroll Today