We will start this course by creating an hello world program with the rust 🦀 programming language.
First, we create a new folder 📂 hello-world and a file 📄 main.rs inside it.
ℹ️
.rsis the extension for rust files.
We can now open the file 📄 main.rs in our IDE, as well as a terminal of your choice, and start writing our program.
We declare a function called main because all rust programs begin with a function main.
// 📄 main.rs fn main() { }ℹ️ the
fnkeyword is used to declare a function.
ℹ️ the lines starting with
//are comments, they are ignored when executing the program.
In the function, we will call the println! macro to print a message to the console. And we pass the string Hello, world! as an argument.
// 📄 main.rs fn main() { println!("Hello, world 👋"); }ℹ️ All instructions end with a semicolon
;
Now that we have coded our program, we will compile it and run it.
to compile the program, we can use the rustc command.
$ rustc main.rsℹ️
$: command
Running this command created an executable file called 📄 main in the current directory that we can run by typing ./main.
$ ./main > Hello, world 👋ℹ️
>: Output of the command
