>> Now, that your development environment
is set up and ready to go,
it's time to write your first program with Rust.
We're going to create a
Hello World program to get you familiar with
how to create and run programs using the Rust compiler.
To begin, go to your terminal or command
prompt and create a new directory for this project.
I personally like to keep all my projects in
a projects directory and then from there I'm going to
take it a step further to create another directory to store
all of my Rust projects that I'll
work on for the series of this course.
To do that I will type
mkdir rust_projects and then
I will cd to rust_projects.
Once inside of this Rust projects directory,
I will make another directory called hello_world
and then I will change directories to the hello_world directory.
Then from there what I want to do is open up
this directory in Visual Studio Code
so I can start writing this Hello World program.
To do that, I can type code space.,
and that will be the shortcut to
open up Visual Studio Code for my terminal.
If that doesn't work for you,
you will need to make sure
Visual Studio Code is added to your path.
If you're on Windows this would have been
done automatically during installation.
But if you're on a Mac like me,
you might have to do this manually.
You can add a shell command to install code in
your path directly from Visual Studio Code.
Let me demonstrate how to do that now.
Once in Visual Studio Code,
I will use the command palette.
To do that, I can type
Command Shift p to open the command palette,
and type shell command and I'll see
this result pop up to install code command and path.
I can go ahead and select that.
After this, the terminal will need to be
restarted for these changes to take effect.
Focusing our attention on VSCode now,
I will select to create a new file named main.rs.
To do that, I will hover over the project name and select
this icon to create a new file and I will title this main.rs,
RS being [inaudible] extension for Rust programs.
I'm going to start up by creating a function called main.
Inside of these curly braces,
what I will do will write out
the message Hello World to the terminal.
To do that, I will use a macro called
println and that macro looks like this, println,
followed by the exclamation and then I
can put the message inside surrounded by quotes,
"Hello, World!"
Then I'm going to go ahead and close that line with a semicolon.
Now, I have a very simple Hello World program.
I need to go ahead and save that.
To do that, I will type command S.
Now what I want to do is compile and run the program.
I'm going to use the terminal that's built into the S Code.
To open up that terminal I can go up
to the top menu and select terminal,
new terminal or also use the shortcut,
which for me is control tilda.
Once there, what I want to do is
first just confirm that I'm in the directory I expect.
Now what I want to do is type rustc main.rs.
This rustc command is going to go ahead and compile my project and
produce a binary executable file
in the same way C or C++ would do.
Now if I were to type LS,
I would see that in addition to main RS,
I also have this main program here.
If you were on Windows,
you would see a main.exe executable file.
Now I can go ahead and run
this program, this binary executable./main.
On Windows it would be slightly different where
again you would be running the main.exe.
Once I enter here,
I can see the output and my terminal says Hello World.
With that, you have completed writing, compiling,
and running your first program.
Congratulations [MUSIC]