Learn Rust Easily - Lesson 1 - Hello World
6K views
Dec 11, 2024
Learn how to program Rust quickly and easily. In this lesson we cover: 1. Why Rust is Awesome 2. How to Install Rust 3. Create Your FIrst Program 👍 Subscribe for more: https://bit.ly/3lLybeP Read this: https://doc.rust-lang.org/book/ ⏱️ Video Chapters 0:00 Intro 1:04 Why Rust 1:27 Installing Rust 2:09 Hello World 🏷️ Tags #rustlang #programming ---
View Video Transcript
0:00
have you ever wanted to be able to code
0:01
and rust to make your programs blazingly
0:03
fast fearlessly concurrent or just plain
0:05
awesome well today you're in luck
0:07
because in this series I'm going to take
0:08
you from rust zero to rust hero and
0:11
since we're about to embark on an
0:13
awesome coding journey together let me
0:14
know why you are on this ship in the
0:16
comments below so what are you going to
0:18
learn today you're going to learn why
0:19
rust is awesome how to install rust on
0:22
your computer and we'll also create your
0:24
first rust program but before we get
0:26
started a little bit about me my name is
0:28
Leo and I've been progr python for about
0:31
a decade now and on my first birthday I
0:34
graduated with a computer science degree
0:36
21 years ago okay maybe it wasn't on my
0:39
first birthday and I'm still young at
0:41
heart but uh I started learning rust
0:43
because I ran into speed and safety
0:45
issues When developing my automated
0:47
trading algorithm that's my why so
0:50
what's yours did you remember to post
0:51
your why in the comments below and
0:53
speaking of old programming languages
0:55
have come a long way in the last 52
0:57
years but two massive problems have
1:00
remained a giant headache for developers
1:01
I like to call them M&M's but they're
1:03
definitely not that sweet the two
1:05
problems are multi-threaded code and
1:08
memory safety but with rust all that
1:10
changes due to Innovative use of
1:12
ownership moves and borrows and while
1:14
you're likely not to understand what
1:16
this means just yet you will by the end
1:17
of the series but what you can
1:19
understand is that rust is awesome
1:21
because it's super fast and safe and
1:23
usually you only get one of the other
1:25
but with rust you get both so now let's
1:27
get this bad boy installed installing
1:29
rust is is super easy all we need to do
1:31
is go to rust-lang org click get started
1:35
and then copy this script right here
1:37
what this does is it uses curl to
1:40
download the rustup script at sh. rust
1:43
up. RS and then passes it to Shell you
1:46
can see when I run it it downloads the
1:48
installer I'm going to press one for the
1:50
default and you'll notice that there's a
1:52
warning CU I already have rust installed
1:54
and to check to see if it installed
1:56
properly you can type rust up update
1:58
this will update rust and you can also
1:59
check the compiler version rust c--
2:03
version you can see that I'm on Rust
2:06
1.76 now before we start creating some
2:08
blazingly fast code we want to make our
2:11
IDE or editor blazingly awesome yeah
2:14
that didn't sound great but whatever um
2:16
what you want to do is go to your
2:17
extensions and make sure you have rust
2:19
analyzer installed you click install and
2:21
if you can see what rust analyzer does
2:23
it provides code completion you know
2:25
Imports definitions things like that so
2:27
it just makes things so much easier here
2:30
so once that's installed we can go ahead
2:32
and create our first rust program and
2:35
we'll start by creating a new file we'll
2:38
call this hello. RS and then we will
2:41
create a main function the main function
2:43
is a primary entry point for rust and
2:45
many other languages so we'll create an
2:46
FN for new function we'll call it main
2:50
we're not passing in any parameter so
2:53
there you know there's nothing between
2:54
the left and right parentheses then we
2:56
have two curly brackets we type print X
2:59
exclamation mark Cuz we're actually
3:00
using a macro here hello comma world and
3:04
then we'll end this with a semicolon
3:08
save it and then we want to go ahead and
3:10
compile it so we'll type rust C and then
3:14
we will enter our file name which is
3:16
hello.rs and you'll notice when we do
3:18
that it creates another file that is the
3:21
binary to run it so we'll type hello and
3:25
that runs it I can type LS here to see
3:27
that here's the code and here's the
3:29
binary
3:30
but in truth you're rarely if ever going
3:32
to use Russ C to compile your code
3:35
you're likely going to use cargo which
3:37
is Russ official build system and
3:38
package manager long story short we'll
3:41
we'll dig into all the details later but
3:42
essentially it helps you manage all of
3:44
your dependencies there's some other
3:45
functionality around build automation
3:47
testing and document generation and
3:49
Publishing packages but essentially
3:50
let's just take a look and see what this
3:52
thing does for now and how it helps us
3:54
as a new R developer so we'll type cargo
3:57
new hello world and this will create a
4:00
new folder and in this folder we're
4:02
going to have some additional files now
4:04
we're going to see this cargo. TL file
4:06
which you know essentially tells cargo
4:08
all of our dependencies the version all
4:10
this other stuff we have a g ignore and
4:12
under here we have this Source folder
4:14
and our main. RS file which essentially
4:18
helps us create uh you know this binary
4:21
which we already created and it looks
4:23
extremely similar to what we already had
4:25
before uh with one small difference
4:27
we're using the print macro here and
4:29
we're using the line hello world there
4:31
just so we can get that extra carriage
4:33
return we could use Russ C to compile
4:36
this but instead let's use cargo so CD
4:38
hello world and we'll type cargo run and
4:41
what this will do is it'll actually
4:43
compile it as you can see right here and
4:45
then it also runs it and it has a
4:47
different Target where we can see it's
4:49
Target debug hello world so we can see
4:51
this new folder Target debug and then
4:54
here's our hell World essentially when
4:57
we are developing we're not going to do
4:59
all of the optimizations we would for
5:01
production code it just helps speed up
5:03
the compile times although that's not
5:05
really an issue with just this hello
5:06
world with rust installed and your
5:08
editor blazing fast click on this video
5:10
to take your next steps in your rust
5:25
Journey
#Computer Education
#Java (Programming Language)
#Programming