►
From YouTube: An Introduction to Rust by Sunjay Varma - Rust KW Meetup
Description
This video was recorded during the first Rust KW Meetup in Kitchener-Waterloo, ON, Canada on March 27, 2018.
https://www.meetup.com/Rust-KW/events/247661794/
Sunjay Varma presented an Introduction to Rust aimed at people with knowledge of at least one other programming language. The video covers what Rust is, basic syntax, ownership and borrowing, and an overview of some advanced features (generics and traits).
Talk written and presented by: Sunjay Varma (https://twitter.com/sunjay03)
Recording: Mark Sherry
A
All
right
welcome
everybody.
So,
first
of
all,
thank
you
for
coming.
We're
really
excited
to
host
the
first
rust
meetup
in
kitchener-waterloo.
Hopefully
this
is
the
first
of
many
meetups
to
come.
I
want
to
start
by
thanking
sort
of
allowed
us
to
use
this
room
and
thank
you
to
mark
who
actually
put
all
of
this
together
and
have
the
initiative
to
put
together
rust,
meetup
here.
So
thank
you.
Mark.
A
Would
have
even
happened
had
mark,
contacted
me
and
started
setting
all
this
up
and
then
done
all
of
the
work
to
get
all
of
us
together.
So
thank
you
very
much.
Let's
get
started
at
the
top,
so
I'm
sundae
Barbra
I've
been
programming
in
rust
for
about
two
years
and
I've
written
quite
a
few
projects
in
rust
and
I've
even
contributed
bits
to
the
Russell
binder
today,
I'm
going
to
give
you
what
I
hope
is
a
practical
introduction
to
the
rust
language,
so
there's
a
link
to
my
slides
at
the
bottom
of
the
screen.
A
If
you'd
like
to
follow
along
on
your
own
devices,
please
go
to
that
link
now,
if
you
do
I'm
going
to
start
by
telling
you
a
bit
about
the
rust
programming
language
and
why
you
want
to
use
it,
then,
for
most
of
the
talk
I'm
going
to
give
you
a
practical
introduction
to
the
rust
programming,
language
and
and
I'm
going
to
try
to
take
you
through
an
example
of
implementing
a
small
program.
That's
going
to
play
the
game
to
Tac
Toe
after
that
I'm
briefly
going
to
touch
on
a
few
arrests.
A
Most
advanced
features,
the
great
thing
about
rust
is
that
you
can
very
productively
write
a
lot
of
code
without
even
using
the
advantage
to
talk
about
the
kinds
of
features
that
don't
really
need
to
be
used
on
the
time,
but
when
the
situation
comes
up,
where
they
come
in
handy
you're,
really
glad
that
rest
supports
them.
This
is
great
because
it
means
you
can
learn
rust
a
little
bit
of
time
without
having
to
understand
all
of
it
at
once.
A
So,
let's
start
by
briefly
going
over
what
the
rest
of
our
gaming
language
is
and
why
you
want
to
use
it
in
the
first
place,
if
I
was
given
one
sentence
to
describe
the
rest
programming
language,
this
is
probably
when
I
say
rest
is
a
safe,
productive,
high
performance
and
low
level
programming
language,
that's
a
big
sentence,
so
let
me
break
it
down.
Rust
is
safe,
so
rest
has
automatic
memory
management
without
garbage
collection.
A
That
means
that,
instead
of
having
to
manage
memory
directly
and
that
be
responsible
for
cleaning
that
back
towards
rust,
does
all
of
this
work.
For
you,
the
remarkable
thing
about
this
is
that
rust.
Does
this
without
having
a
garbage
collector
most
languages
that
do
automatic
memory
management
require
having
something
that
either
runs
with
your
program
or
stops
it
completely
in
the
middle
to
free
memory
when
it
stops
being
used.
This
can
impact
the
performance
of
your
program.
A
A
lot
and
rust
is
able
to
avoid
this
and
guarantee
safety,
because
the
rust
type
system
provides
enough
information
for
the
compiler
to
figure
out
exactly
what
a
value
should
be
deleted.
The
mechanisms
for
this
are
called
ownership
and
borrowing
and
I'll
discuss
them
later.
In
the
talk,
the
amazing
thing
about
ownership
and
borrowing
is
that
rust
is
able
to
make
some
pretty
amazing
guarantees
about
your
program.
Any
rust
program
that
successfully
compiles
is
guaranteed
to
be
memory
safe
and
data
free.
A
That
means
that
a
whole
bunch
of
common
memories
are
completely
eliminated.
You
get
rid
of
the
views
after
fries
double
for
these
dangling
pointers,
and
so
many
other
things.
Safety
means
that
a
rust
program
will
never
stick
fault
if
you
use
multiple
threads
rust
catches,
a
lot
of
common
concurrency
problems
that
can
be
really
hard
to
keep
up
even
before
your
program
is
run,
so
rust
is
productive.
You
can
actually
start
writing
production
writing
code
in
rest
today
and
the
reason
I
was
so
confident
about
this
is
because
all
of
these
companies
already
do
that.
A
All
of
these
companies
know
that
rust
is
ready
to
be
used
in
production
in
their
apps,
and
this
is
from
the
Friends
of
rust
page
on
the
rest
website.
I
actually
highly
recommend
that
you
go
to
that
URL
as
you
can
see
exactly
what
each
of
these
companies
is
using
us
for
so
rust
is
designed
to
be
a
productive
language.
You're
actually
meant
to
write
code
in
it
and
use
it
for
things
beyond
small
personal
projects
and
research
like
while
there
are
some
cutting
edge
features
in
rust.
A
A
lot
of
rust
is
based
on
old
established
techniques,
which
have
already
proven
to
be
effective
at
other
languages
in
throughout
the
field.
When
you
use
Russ
type
system,
you
end
up
describing
a
program
in
a
way
that
gives
the
compiler
a
lot
of
power
to
check.
If
it's
correct,
often
just
getting
your
code
to
compile,
it
means
that
you've
already
avoided
a
ton
of
potential
bugs
you
don't
have
to
wait
until
your
program
is
halfway
finished
to
find
out
that
you
did
something
wrong.
A
Rust
is
high
performance,
so
just
like
low-level
languages
like
C
or
C++
rust
gives
you
a
lot
of
control
over
how
your
program
is
represented
and
run
you
get
to
choose
the
train
offs
you
made
between
efficiency
and
memory,
representation.
Russ.
Does
the
majority
that
safety
checks,
correctness,
checks
and
memory
management
decisions
at
compile
time,
so
there's
no
runtime
impact
for
writing.
Safe,
correct
code,
as
I
mentioned
before
trust,
does
automatic
memory
management
without
garbage
collection.
A
All
of
these
decisions
about
allocating
and
freeing
memory
are
made
at
compile
time
so
that
there's
no
impact
on
your
code,
while
it's
running
and
Russ
borrows
the
excellent
concept
of
zero
cost
abstractions
from
C++,
so
that
you
get
to
write
code
that
feels
really
high-level,
but
it's
as
performant
as
if
you've
written
it.
In
a
lower
level,
language,
so
rust
is
low
level.
A
All
of
the
amazing
things
I've
mentioned
so
far,
wouldn't
be
complete
without
mentioning
that
rust
is
a
low-level
language
and
I
put
extra
emphasis
on
this,
because
rust
doesn't
feel
like
a
little
level
language
like
you,
don't
spend
hours,
debugging,
all
kinds
of
crazy
memory,
issues
or
concurrency
bugs
and
even
though
rust
supports
advanced
features.
You
don't
need
to
deal
with
any
of
the
overhead
or
with
any
extra
overhead
because
of
them.
A
So
Russ
gives
you
complete
control
over
your
program
without
forcing
you
to
take
the
entire
responsibility
to
make
sure
that
your
program
is
correct.
You
might
be
wondering,
though,
if
Russ
supposedly
gives
me
complete
control.
How
can
it
also
manage
my
memory
for
me
and
do
so
many
other
things
by
default?
Well,
it
turns
out
that
rust
has
this
concept
of
unsafe.
A
This
is
a
way
for
you
to
tell
the
compiler,
hey,
I,
know
that
so
probably
better.
We
have
a
word
for
this
would
be
unchecked
because,
while
you
can
do
unsafe
things
with
unsafe
most
of
the
time,
you
only
use
it
when
you
have
a
specific
low-level
need
that
safety
guarantees
conflict
with
I'm,
saying
what
to
do:
inline
assembly
or
a
pointer
access
and
all
kinds
of
other
things
that
you'd
expect
a
low-level
language
to
allow
you
to
do
so.
What
is
all
of
this
kids?
So
what
is
all
this
game?
A
A
There's
a
reason
that
rust
has
been
the
most
loved
programming
which,
for
three
years
running
off
the
Stack
Overflow
developers
are
a
now
with
all
that
said,
let's
jump
into
some
rest
I
want
to
give
you
a
practical
introduction
to
rust
and
get
you
to
the
point
where
you
could
at
least
start
to
experiment
with
the
language
and
write
some
programs.
The
way
I'm
going
to
do
that
is
by
getting
us
to
go
through.
A
Writing
certain
parts
of
the
game
tic-tac-toe
as
we
go
through
it,
will
cover
a
lot
of
different
aspects
of
the
Russ
language.
Now
I'm
not
going
to
have
time
to
go
through
the
entire
program
with
you,
so
I've
actually
prepared
a
fully
commented
version
of
the
example
and
thoroughly
commented
it
with
descriptions
of
exactly
what
I
did
and
the
decisions
that
I
made.
So
there's
a
link
at
the
bottom
of
the
slides
that
if
you
want
to
check
that
out
later
now,
let's
start
by
covering
variables
and
functions
so
rust
is
a
statically
typed
language.
A
Statically
typed
means
that
every
value
in
your
program
has
a
specific
type
known
to
the
compiler
at
compile
time.
The
way
that
rust
gives
you
all
of
the
benefits
that
I
described
is
by
knowing
a
lot
about
your
program.
Through
these
types,
rust
has
a
feature
called
type
inference,
which
means
that
the
Russell
Pilar
can
figure
out
most
of
your
types
for
you.
So
even
though
it
has
types,
you
often
don't
even
need
to
write
them.
A
Functions
in
rust
are
one
of
the
few
places
where
you're
required
to
put
type
annotations.
This
is
actually
great
because
it
gives
you
a
completely
obvious
way
to
know
exactly
which
values
the
function
expects
just
by
looking
at
its
type
signature
in
Ross,
the
syntax
for
annotating
types
on
variables
is
the
same
as
the
syntax
for
annotating
types
and
functions.
You
put
the
type
after
the
name
using
a
colon
to
separate
the
two.
The
return
type
is
annotated
after
the
function.
Arguments
using
the
arrow
you
see
pointing
to
by
32.
A
This
example
also
shows
another
aspect
of
rust,
which
is
that
the
last
expression
of
the
function
is
used
as
a
return
value
from
that
function.
So
here
you
see
that
x
and
y
are
put
on
their
own
lines
without
a
return,
keyword
or
a
semicolon.
That
means
that
one
or
the
other
will
be
the
result
of
the
if
statement,
and
then
that
will
be
returned
in
the
function.
Since
the
if
statement
is
the
last
expression
and
the
function
spike.
A
A
few
minutes,
the
complete
tick,
typed
or
example
that
I
mentioned
with
it's
fully
commented,
has
a
couple
of
different
places
where
we
used
or
trained
explicitly
to
exit
a
function
early
when
we
know
that
we
definitely
shouldn't
come
on
so
here's
some
common
rest
types
that
you
should
keep
in
mind
throughout
the
rest
of
the
talk
and
we
won't
use
the
majority
of
them.
So
don't
worry
about
memorizing
any
of
them
now,
but
it's
good
to
know
that
they
exist.
A
So
rest
is
five
unsigned
integer
types,
the
number
after
the
letter
U,
represents
the
number
of
bits
in
that
title.
So
you
32
is
a
32-bit
unsigned
integer
type.
This
same
convention
is
used
for
all
other
types
as
well.
There
are
five
signed,
integer
types,
the
types
you
see
at
the
end
use
size
and
eyesight's
are
a
little
special
because
they're
used
to
index
arrays
relax
their
representation
depends
on
your
platform
in
architecture.
A
We
have
the
chart
type
and
there
are
two
string
types
both
with
fully
your
code
support,
the
second
string
type
you
see
there
is
a
global
string
type
and
it's
allocated
on
the
heap
rust
as
a
unit
type,
which
is
kind
of
like
for
you
in
other
languages,
but
not
so
much
of
a
special
case
and
Russell
also
had
a
special
compound
types
like
option
which
we'll
discuss
later
and
tuples
and
fixed
on
his
trace.
These
types
can
contain
other
types
like
the
ones
I
just
mentioned.
A
Russ
can
have
all
the
amazing
features
in
the
world,
but
if
you
didn't
have
great
tools
to
match
them,
it
would
fail
as
a
language
like
it's
really
hard
to
use
a
language.
If
building
and
running
your
code
is
difficult
to
do,
luckily,
rust
has
great
tools
in
its
ecosystem,
including
the
excellent
package
manager
and
built
tool
called
cargo.
We
can
start
our
tic-tac-toe
application
by
using
carbon
to
create
and
run
it
to
create
a
new
project
with
cargo.
All
we
have
to
do
is
run
the
command
cargo
new
and
provided
with
the
project
name.
A
We
can
then
run
the
command
cargo
run
to
compile
and
run
our
program.
It's
really
that
simple,
like
there's,
just
two
commands
to
get
set
up
and
get
started,
and
we
won't
talk
about
tools
very
much
after
this,
but
you
should
know
that
rust
prides
itself
on
having
very
easy
to
use
and
healthy
tools
that
are
easy
to
learn.
A
Let's
get
back
to
the
language,
so
we've
covered
variables
and
functions.
So
now,
let's
move
on
to
two
very
important
that
we'll
use
to
start
our
detective
application,
structs
and
enums.
We
need
some
way
to
represent
the
game
board
and
the
pieces
that
can
go
on,
strikes
and
rest.
Look
something
like
this.
You
give
the
start
to
name
and
then,
with
each
field
you
specify
the
type
after
a
col.
This
is
similar
to
what
you
saw
with
functions
and
with
barriers.
A
These
are
a
little
different
from
the
start,
so
you
might
have
seen
in
other
languages
because
struck
fields
are
proud
of
it
and
there's
no
classes
in
rust.
The
struct
is
going
to
be
used
to
represent
our
tic-tac-toe
board.
Its
first
field
is
a
2-dimensional
array
of
pieces,
because
the
tic-tac-toe
board
is
two-dimensional.
This
is
the
syntax
for
declaring
the
type
of
a
fixed
sized
array
in
rust.
We
put
a
type
name
and
then
the
size
of
the
array.
A
After
is
n
equal
by
nesting
that
syntax
we
can
get
the
we
can
get
an
array
of
arrays
which
we'll
use
to
represent
the
rows
of
our
orc.
The
second
field
is
used
to
store
the
piece
whose
turn
it
is
to
move,
and
the
last
field
is
where
we
store
the
winner
of
the
game
once
became
this
complete.
The
reason
we
started.
A
That
is
because
it
takes
a
couple
of
seconds
like
it
takes
quite
a
bit
of
computation
to
compute
the
winner,
and
so
we
don't
want
to
do
that
over
and
over
again,
and
so
we
store
it
and
only
said
it
was
option
which
you
see.
If
you
mentioned
a
couple
of
times,
lets
us
represent
that
titles
might
be
empty
like
there
might
not
be
any
piece
there,
and
it
also
lets
us
represent
that
there's
no
winner
in
the
game
until
the
game
ends
and
we'll
talk
about
that
more
in
just
a
minute.
A
Enums
are
how
we
represent,
having
multiple
possible
alternatives
for
a
value,
and
you
tile
on
board
that
has
a
piece
can
have
either
X
or
o,
but
never
both
the
game
can
end
with
either
X
winning
a
winning
or
neither
waiting
at
a
time,
but
only
those
can
be
the
case
at
any
given
time.
He
knows
already
natural
way
to
represent
these
choices,
and
you
know,
stress
can
actually
be
even
more
powerful
than
what
we
see
here.
A
Each
variant
can
have
different
fields,
so
you
can
pass
even
more
information
depending
on
the
situation,
option
and
result
which
we'll
see
in
the
next
slide
are
excellent
examples
of
iums
that
have
fields.
The
complete
detective
example
I,
give
them
uses
this
feature
to
provide
more
context
about
different
areas
that
can
occur
when
theythey
loop.
A
Now,
let's
talk
about
two
very
important
features
in
rest:
option
and
result.
Rest
uses
these
types
instead
of
having
a
no
value
or
having
exceptions
if
you've
ever
dealt
with
either
of
those
extensively.
You
know
that
both
Nava
and
exceptions
have
big
drawbacks
that
can
make
them
really
frustrating
to
use
rustics
all
that
away
with
these
two
types.
The
first
thing
you
should
notice
is
that
both
option
and
result
are
just
regular.
A
Enums,
like
the
ones
we
saw
on
the
previous
slide
option,
is
a
type
that
represents
the
possibility
of
there
being
some
value
or
no
value
the
some
variant
of
the
option.
You
know,
stores
a
field
of
some
type.
T
now
don't
be
afraid
of
those
angle
brackets
they
just
mean
that
T
can
be
any
type.
If
there's
no
value,
you
use
nothing
by
using
items
like
this
and
not
having
a
special
null
value.
You
always
know
exactly
when
you
need
to
think
about
the
possibility
of
some
value
being
there.
It's
never
a
surprise.
There's.
A
Never
a
nullpointerexception
rust
ensures
that
you
don't
forget
to
handle
the
case
when
you
need
to
result
is
used
for
what
an
operation
might
fail.
It
has
to
marys
okay
and
error,
which
both
have
one
field.
If
an
operation
is
successful,
you
use
okay
to
provide
the
complete
another.
If
something
was
problem,
you
use
error
to
provide
an
error
value
that
tells
you
what
happened
well.
A
So
this
function
takes
the
strength
of
user
input
and
attempts
to
convert
it
into
a
row
and
column
index
that
correspond
to
that
it
corresponds
to
the
fourth.
The
top
line
of
this
slide
shows
how
we
display
the
game
board
to
the
user.
The
columns
are
lettered
ABC
and
the
rows
are
number
one.
Two
three.
We
want
the
user
to
enter
something
like
one
C
and
then
we
want
to
convert
that
into
a
position.
A
0
2,
since
what
is
the
first
row
and
C
is
the
third
row
since
the
user
could
provide
any
input
at
all.
This
function
has
the
possibility
of
failing
to
model
that
we
use
the
result
type
as
the
return
type
of
this
function.
You
can
read
this
function
as
parcel
of
takes
a
string
as
its
argument,
and
if
it
is
successful,
it
returns
a
pair
of
unsigned
integers.
A
If
it
fails,
it
returns
a
type
called
in
Malibu,
and
now
the
loop
is
defined
at
the
that's
kind
of
you
know,
loom
is
defined
at
the
bottom
and
is
similar
to
the
starts
you
saw
earlier.
It's
actually
called
a
tuple
strength
and
it
only
has
a
single
field
for
the
invalid
string
that
we
want
to
tell
the
user
about.
A
So
this
function
starts
by
checking
everything
length
of
the
string
is
not
equal
to
2.
If
that's
the
case,
we
already
know
this
could
never
be
a
valid
input,
so
we
return
right
away.
This
is
the
first
time
we've
seen
the
rejection
explicitly
and
it's
really
useful,
because
we
know
that
we
want
to
return
early
from
the
function
as
soon
as
this
error
is
found.
A
Next,
we
see
two
matched
statements
when
statements
are
kind
of
like
switch
statements
and
other
languages,
but
even
one
powerful.
Each
line
in
the
match
statement
starts
with
a
pattern
and
if
the
pattern
matches
the
rest
of
the
line,
oh
and
if
the
pattern
matches
the
rest
of
the
line
to
the
right
of
the
arrow
is
returned.
So
the
first
match
statement
we're
looking
at
three
patterns
for
each
possible
string
that
can
be
provided
as
a
row
number
if
any
of
them
match.
A
You
return
the
correct
row
index
and
put
that
in
the
variable
row
the
variable
call
is
similar
and
it's
said
to
be
correct
column
index
based
on
a
letter
provided
in
the
input
notice
that
we
can
use
a
vertical
bar
or
pipe
character
to
separate
different
patterns.
If
any
of
those
match
the
right
side
of
the
arrow
is
returned.
So
this
lets
us
do
what
we
also
could
have
done
with
many
of
statements
in
just
a
few
lines
of
code.
A
Let
me
go
back
to
the
first
nastiness
of
the
underscore
their
matches
a
pattern,
and
we
use
that
to
return
the
entire
strength,
but
in
the
second
match
statement
we
see
that
we
can
use
variables
in
the
match
and
I
just
want
to
highlight
this
is
this
was
just
before
the
video
got
cut
off.
So
what
that
second
match
statement
does.
Is
it
takes
the
character
that
we're
mashing
on
and
it
puts
it
in
that
variable
in
belt,
and
that
lets
us
provide
even
more
specific
error
message
to
the
user.
A
Finally,
if
both
of
my
statements
succeed,
we
return
a
successful
result
from
the
function
using
okay.
This
is
the
other
very
active
result
that
we
use
in
case
our
computation
is
successful.
Now.
The
key
thing
to
note
here
in
all
of
us
is
that
we
aren't
running
exceptions
when
we
come
across
an
error
case
errors,
don't
have
to
be
a
special
case
in
your
language.
A
Instead
we're
considering
an
instance
of
a
regular
type
call
result,
it's
just
a
regular,
you
know,
and
returning
either
is
successful
value
or
an
appropriate
error
based
on
what
happens
just
like
the
option
by
using
result,
rust
allows
you
to
be
sure
that
you
handle
errors
when
you
need
to,
and
then
you
don't
need
to
worry
about
than
otherwise.
You
never
have
to
be
surprised
about
an
exception.
A
Mom
on
your
program.
This
way
makes
it
really
hard
to
accidentally
forget
a
case
that
you
should
have
accounted
for
now.
Let's
spend
a
few
minutes
and
talk
about
ownership
and
horrible.
These
are
two
foundational
features
of
rust
and
understanding
that
will
help.
You
see
how
the
language
is
able
to
make
such
strong
guarantees
about
things
like
memory,
safety
and
freedom
for
daenerys's
ownership
allows
us
to
know
exactly
when
we
can
free
a
certain
piece
of
memory,
and
there
are
three
ownership
rules.
A
If
you've
ever
used,
smart
pointers
and
languages,
these
will
be
familiar
to
you.
The
first
tool
is
that
each
value
in
rust
has
a
variable.
That's
called
as
omen.
The
second
rule
is
that
there
can
only
be
one
owner
at
a
time,
and
the
third
rule
is
that
when
the
owner
goes
out
of
scope,
the
value
will
be
dropped.
A
Dropping
the
value
is
the
same
as
freeing
its
memory
or
deleting
it,
and
these
three
rules
are
at
the
core
of
the
rust
programming
language
and
how
it
works
every
variable
you
create
both
data
and
then,
when
that
variable
goes
out
of
scope,
the
data
that
it
owns
is
dropped,
since
there
is
only
one
owner
at
a
time,
there's
no
complicated
decisions
that
need
to
be
made
when
that
need
to
be
made
when
we're
determining.
If
we
can
drop
the
very
as
soon
as
the
only
variable
goes
out
of
scope,
we
drop
it
stop.
A
So
this
is
how
rust
manages
your
memory
for
you
without
needing
a
garbage
collector
at
runtime.
Now,
if
we
could
only
have
a
hold
on
to
a
value
in
one
variable,
at
a
time,
we
wouldn't
be
able
to
write
a
lot
of
useful
programs.
So
this
is
where
borrowing
comes
in
handy
borrowing
allows
us
to
temporarily
use
the
data
owned
by
another
variable.
This
lets
us
pass
a
value
to
the
function
without
moving
the
malian
and
transferring
ownership.
I'll
show
you
what
I
mean
by
them.
A
In
this
example,
the
string
hello
world
is
owned
by
the
variable
X.
When
we
pass
it
into
the
function,
its
value
is
moved
into
that
function,
because
the
second
ownership
rule
says
that
there
can
only
be
one
order
at
a
time
if
the
function
needs
to
operate
on
the
value
it
needs
to
own
it
as
well.
That
means
that
when
we
try
to
print
X
after
calling
the
function,
it
can't
work
because
X
was
moved
into
the
function
and
then
dropped
when
the
functions
parameter.
A
Went
to
the
scope,
so
if
we
try
to
compile
this
rust
immediately
catches
our
error
and
tells
us
exactly
what
happened,
we
tried
to
use
a
value
that
it
already
and
the
error
message
tells
us
exactly
where
the
value
was
moved
to
and
which
line
tried
to
use
it
afterwards.
We
can
fix
this.
Using
borrow.
A
The
ampersand
is
how
we
borrow
X.
This
creates
a
reference
10x
and
passes
a
to
the
function
instead
of
moving
x's
value
that
it's
entire.
The
functions
type
also
changes
now
to
take
the
poor
on
string
instead
of
moving
the
value
like
it
was
doing
before
now.
When
the
function
ends
it
just
drops
of
reference
to
X
and
n
is
the
borrower?
X
is
still
owned
by
its
original
variable,
so
that
means
we
can
print
out
the
value
successfully
and
this
code
works.
A
There
are
actually
two
different
kinds
of
references,
and
the
rules
about
them
are
how
rust
prevents
data
races.
So
just
a
single
ampersand
is
called
an
immutable
reference,
and
this
allows
you
to
borrow
some
data,
but
not
change
it,
and
then
the
other
type
of
reference
is
called
a
mutable
reference
and
you
can
use
it
to
change
the
value.
A
This
prevents
data
races,
since
those
can
only
occur
if
you're
allowed
to
both
read
and
write
to
the
same
data
at
the
same
time,
by
forcing
you
to
only
do
one
or
the
other
rust
makes
it
impossible
for
you
to
ever
run
into
this
problem,
for
you
to
ever
have
a
data
race.
The
second
rule
is
that
references
must
always
be
popped.
A
Let's
complete
our
discussion
of
the
language
by
briefly
touching
on
two
advanced
features
in
Russ
type
system.
I
wanted
this
to
be
a
practical
introduction,
so
I
focused
more
on
the
fundamental
features
of
Russ
and
in
fact
the
entire
tic-tac-toe
application
is
actually
written
without
really
even
using
either
of
the
features
I'm
about
to
discuss.
A
Rust
is
a
productive
language
that
you
do
not
need
to
learn
in
its
entirety
in
order
to
enjoy
the
productivity.
The
advanced
features
are
such
that
they
aren't
required,
but
when
you
do
come
to
need
them,
you're
really
glad
that
they're
there.
So
the
two
features
that
I
want
to
touch
on
are
called
generics
and
traits,
and
you
may
have
noticed
some
angle
brackets
and
some
of
the
code
that
I
showed
you
earlier
for
option
result
I'm,
going
to
explain
what
that
is
now
generics
are.
A
Generic
types
are
just
a
way
to
write
types
and
functions
that
can
work
on
a
variety
of
different
types.
It
turns
out
that
a
lot
of
code
doesn't
really
depend
so
much
on
the
specific
types
that
you
provided
so
generics
help
us
avoid
duplication
by
allowing
us
to
write
a
single
type
or
function
that
can
be
used
on
any
type.
That
would
make
sense.
Let's
look
at
an
example.
This
function
adds
two
things.
The
angle
brackets
are
used
to
declare
a
generic
type
T.
A
This
says
that
we
want
Russ
to
put
in
any
type
that
works
and
use
it
as
the
parameters
and
return
type.
The
problem
is
that
this
function
won't
actually
compile
in
its
current
form
in
terms
of
it
when
we
said
anytime,
rust
really
interpreted
that
as
any
type,
but
not
necessarily
every
time
can
actually
be
added.
So
this
is
where
traits
come
in
handy.
A
A
trait
is
like
a
collection
of
methods
that
we
expect
a
type
to
implement,
and
it
turns
out
that
there's
something
called
the
atom
trait
in
the
in
first
standard
library
that
the
compiler
uses
to
figure
out
how
to
add
two
values.
So
if
we
put
a
colon
after
our
Declaration
of
T
and
specify
that
we
wanted
to
implement
added,
we
can
mostly
fix
the
issue,
because
this
tells
for
us
that
we
don't
want
just
any
type.
A
A
So
this
concludes
our
whirlwind.
Tour
of
the
rest,
programming,
language,
I,
hope
the
features
I
talked
about
in
the
syntax.
That
I
was
able
to
cover
picture
interest
and
made
you
want
to
learn
more
about
the
Russ
programming
language.
Once
again,
I
really
encourage
you
to
check
out
the
fully
commented
version
of
the
tic-tac-toe
application.
It'll
teach
you
a
lot
more
than
I
could
have
covered,
and
it's
a
complete
example
of
writing
a
rest
application
without
any
of
the
advanced
features
that
I
just
talked
about.
A
There's
a
lot
that
I
didn't
cover,
but
you
should
definitely
go
and
learn
about.
Rest
has
a
lot
of
really
nice
features
to
make
writing
software
really
easy,
and
it's
a
very
cool
and
exciting
language
that
you
can
actually
start
to
use
seriously
right
now.
The
Russell
book
is
especially
great
and
kind
of
highly
recommended
I'm,
also
personally,
working
on
a
free
online
course
to
help
people
learn
programming
from
scratch
using
Russ
I
like
this
talk
the
course
will
have
no
prerequisite
knowledge
required.
A
That
means
that
anyone,
regardless
of
background,
will
be
able
to
learn
how
to
program
it's
still
in
the
process
of
being
completed.
But
you
can
expect
to
see
some
lessons
start
to
appear
over
the
next
few
weeks.
The
really
unique
thing
about
this
course
is:
they
will
teach
programming,
but
I
have
draw
pictures
instead
of
getting
you
to
read
and
write
text
like
most
traditional
programming
language
courses,
it
should
be
a
lot
of
fun
for
anyone
of
any
age
or
skill
level.
So
please
do
check
it
out.