►
From YouTube: GWO 2014: Steve Klabnik, "Rust For Language-ists"
Description
Slides: http://steveklabnik.github.io/nobody_knows_rust
Great Wide Open: http://greatwideopen.org
A
Okay,
this
talk
is
called
rust
for
languages
and
the
reason
it's
called.
That
is
because
I
love
the
litter.
A
shin
I
am
nominally
a
Ruby
programmer
I.
Do
that
the
most
of
my
time
is
in
Ruby
and
so
I
wrote
a
community
tutorial
called
rust
for
rubios
a
little
over
a
year
a
year
a
half
ago,
now
Wow
time
flies
about
Mozilla's
programming,
language
of
rust,
and
so,
rather
than
making
this
be
about
rust
for
rubios.
This
is
a
more
general
rust
for
programmers
that
are
interested
in
Mozilla's
rest.
A
If
you,
hopefully
our
super
psyched
about
it
like
I,
am
so
those
are
sort
of
the
big
three
sections
to
this
talk
so
about
the
language
itself,
who
is
familiar
with
rust
at
all?
By
the
way,
is
this
gonna
be
cool?
So
I
got
some
people
a
little
bit.
Awesome
I
will
go
into
all
the
details,
then
rusts.
So
rust
is
a
really
interesting.
A
New
programming
language
I
say
that
it's
interesting
because
it's
doing
a
lot
of
stuff
that
is
really
unique
and
it's
also
innovating
in
a
space
that
has
not
seen
significant
amounts
of
new
things
in
a
while.
Basically,
rust
is
a
good
choice.
When
you
would
choose
C++,
that's
how
you
primarily
should
think
about
rust
is
I
need
super
low
level.
Control
I
need
to
make
sure
that
I'm
manage
my
memory
allocations
correctly.
A
I
want
to
do
all
these
things,
so
I
use
C++
rust
would
be
a
replacement
for
all
of
the
use
cases
as
C++
is
used,
for
it
also
may
be
useful
at
other
times.
So,
like
I
said
I
program
in
Ruby
most
days
and
I
got
really
interested
in
rust
and
there's
actually
a
significant
chunk
of
rubios
and
Python
mistahs
ethin
East
a--'s
in
rust
world.
So
you
sort
of
have
people
that
are
coming
from
the
super
low
level
systems.
A
I
want
a
better
C++
and
you
have
people
coming
from
even
the
like:
Haskell
and
ml
community.
You
have
like
high
level
people
who
are
interested
in
doing
more
low-level
stuff.
It's
kind
of
these
dual
sides
in
in
three
like
semi,
buzzword,
things,
rusted,
the
system's
language:
that's
pursuing
the
trifecta
of
safe
concurrent
and
fast.
So
the
primary
thing
rust
is
concerned
about
is
safety
and
we'll
talk
more
about
what
that
means
later.
But
that
is
the
driving
force
of
everything
else
in
the
language.
A
So,
for
example,
rust
does
not
have
tail
call
optimization,
because
it
cannot
actually
guarantee
certain
things
about
its
safety,
and
so
until
someone
fixes
the
theoretical
holes
in
that
system,
rust
will
not
juice
TCO,
because
safety
is
paramount.
Above
all
else
concurrency.
This
was
originally
an
explicit
design
goal,
but
it's
sort
of
fallen
out
of
the
safety
design
goal
so
because
rust
is
memory
safe,
it
wants
to
be
concurrent
really
well
and,
as
it
turns
out,
concurrency
is
generally
not
safe,
so
provide
providing
safe
language
primitives.
A
We
actually
make
concurrency
significantly
easier
to
write
and
reason
about
in
rust,
as
opposed
to
other
languages.
Sorry
what
that
means,
and
finally
fast
you
can't
replace
C++
without
being
as
fast
as
C++
and
so
most
of
the
stuff
that
rust
does
is
actually
at
compile
time,
so
it
will
actually
compile
what
looks
like
a
more
complicated
structure
into
something
that
is
the
equivalent
assembly
that
would
be
generated
by
a
C++
compiler,
and
so
the
like.
The
goal
is
to
be
like
if
we're
within
10
burst.
A
If
we
are
not
within
ten
percent
of
the
speed
of
C++,
we
have
failed
utterly,
and
hopefully
it
will
be
equivalent
and
maybe
even
some
times
faster,
maybe
maybe
in
the
future.
So
those
are
the
three
big
things
that
rest
is
all
about.
I've
been
toying
around
this
idea
of
calling
rust
an
ownership
oriented
programming
language
because,
as
we
all
know,
every
new
language
needs
its
own
set
of
buzzwords
to
generate
its
own
set
of
blog
posts
and
conference
talks
and
books
and
shenanigans.
So
I've
been
joking.
A
A
So
the
origins
rust
is
written
by
this
man
named
Graydon
and
he
works
at
Mozilla
and
he
basically
was
building
this
language
in
his
spare
time.
So
he
was
originally
originally
originally
writing
a
C++
compile
because
there
are
people
who
write
C++
compilers
for
fun
and
at
that
point
at
some
point
he
got
to
a
certain
education,
the
spec,
and
he
was
like.
Why
am
I
doing
this?
This
is
terrible.
We
should
make
a
better
language
just
like
how
everyone
starts
right.
Many
many
a
programmer
has
fallen
to
the
C++
is
terrible.
A
I'm
gonna
do
it
better,
but
Graydon
actually
persevered
and
he
got
a
job
at
Mozilla
and
about
the
time
I
think
it
was
like
two
years
into
the
development
of
rust.
He
was
working.
Mozilla
and
Mozilla
wanted
to
spin
up
an
R&D
division,
and
so
they
were
like
looking
for
interesting
projects
to
go
under
the
new
rd
umbrella,
and
so
the
CTO
of
mozilla,
brendan
eich
head
said
specifically
like
hey
I,
think
rust
is
super
cool,
but
I'm
not
sure
how
it
fits
into
Mozilla's
vision.
A
Could
you
pitch
me
on
why
I
should
make
rust
the
first
project
of
Mozilla's
rd
branch
and
Graydon
managed
to
convince
him
which
I'll
explain
why
in
a
second,
but
then
so
basically
became
an
official
research
project
of
Mozilla
and
they
now
pay
people
to
work
on
a
language.
Full-Time
Graydon
is
actually
no
longer
in
charge
of
the
language
he
has
moved
on
to
other
things
and
we
have
a
new.
You
know
person.
So
in
some
degrees,
that's
its
own
definition
of
maturity.
Right
is
when
your
project
outlives,
you
that's
when
it's
like
real.
A
So,
there's
interesting
that
the
reason
that
that
mozilla
decided
to
take
on
Russ
is
that
Mozilla
writes
a
lot
of
C++
code
like
Firefox
is
massive
right
and
they
also
feel
the
pain
of
writing
lots
of
C++
code.
So
unless
you
have
written
a
lot
of
C++
and
sort
of
have
like
Stockholm
Syndrome
about
it,
writing
C++
is
terrible.
I,
like
straight
up,
see
better
than
C++
it
personally,
but
there's
good
reasons
to
use
it
in
certain
times
and
I.
A
Don't
think
that
they're
wrong
for
using
it,
but
they
feel
the
pain
of
using
it
and
there's
that
pain
comes
across
in
multiple
ways.
Sometimes
it's
compilation
times,
sometimes
its
security
vulnerabilities,
so,
for
example,
the
pwned
to
own
competition
that
happens
every
so
often
where
security
researchers
get
together
and
try
to
hack
web
browsers
in
the
last
pwned
to
own.
All
three
of
the
bugs
that
were
found
in
firefox
were
all
related
to
essentially
mismanage
pointers,
so
two
of
them
were
buffer
overflows.
A
The
last
one
was
like
a
mismanage
like
pointer
to
some
arbitrary
point
memory.
Remember
the
details,
but
the
point
is
it
was
C++
problems
like
in
a
language
that
Nazi
plus
those
would
not
have
happened
so
those
lead
to
security
vulnerabilities.
They
lead
to
like
terrible
refactoring
problems,
so
Firefox
does
not
currently
have
the
one
process
per
tab
thing
that
other
browsers
have
and
the
reason
why
is
it
when
someone
actually
spect
out
like
what
it
would
take
to
rewrite
the
relevant
chunks
of
gecko?
To
make
that
happen?
A
They
estimate
it's
about
18-month
project,
so
they're
like
working
on
it,
but
it's
going
to
take
a
while
and
it's
going
to
take
a
while,
because
that's
not
a
non
significant
improvement
and
code
bases
that
have
grown
over
decades
are
complicated
right
so
and
you
have
to
be
super
careful
because
if
you
miss,
if
you
screw
up
one
pointer
your
host,
so
it's
like
very
very
hard
to
do
so.
So
that's
why
Mozilla
cares
about
this
language
stability.
This
is
the
one
problem
with
rust
at
the
moment,
but
it's
getting
better.
A
This
slide
says
currently
that
will
not
technically
be
true
until
like
tomorrow
afternoon,
so
currently
was
watching
this
video
later
rust
is
a
version
0.2
N
and
basically
every
release
is
a
three
month
snapshot
of
whatever
happened.
So
0.9
was
almost
three
months
ago.
Actually,
maybe
even
they
released
20
10
today,
I'm,
not
sure
it
is
this
week
as
when
0
10
is
coming
out.
So
I
made
all
these
slides
I
made
I
checked
them
as
version
of
the
compiler
from
yesterday.
A
So
there
shouldn't
be
any
last
moment
significant
changes
in
this
code,
but
it's
currently
snapshot
development,
so
they're
not
backwards
compatible
at
all.
A
one
point
0
is
coming.
This
says
soon.
It's
actually
like
this
year
is
what
soon
means,
and
at
the
one
point
0
mark
rust
will
become
super
stable
and
not
break
anything
and
beasts
mega
backwards
compatible.
A
So
it's
been
about
five
years
of
development
currently
in
to
rust
and
lots
of
stuff
changes
every
release,
because
we
currently
discover
better
and
better
ways
of
doing
all
the
things
that
we're
doing
and
where
I
think,
there's
47
backwards,
compatible
changes
that
are
left
to
happen
before
10.
Actually,
so
it's
getting
there
and
it's
very
close,
but
this
is
the
problem
about
using
rust
today-
is
that
you
basically
have
to
pay
attention
to
people
say
like
oh
you're,
using
a
compiler
for
two
months
ago.
That's
really
old!
A
You
should
like
recompile
your
compiler,
and
it
makes
it
hard
to
learn
with
tutorials,
because
they're
significantly
out
of
date
after
a
period
of
time.
So
that
is
the
problem.
It
will
be
fixed
at
one
point:
oh
I'm
telling
you
about
this
because
a
couple
reasons.
First
of
all,
as
we
approach
one
point,
oh
you
want
to
get
more
people
involved
who
have
not
seen
the
language
before,
because
they're
the
ones
that
are
hopefully
going
to
end
up
using
it,
and
you
want
them
to
raise
any
red
flags
before
the
one
point.
A
0
release
actually
happens
and
we
make
that
promise
forever
right.
So
the
worst
possible
thing
you
can
do.
This
is
always
my
least
favorite
part
about
I-I've
commit
to
rails
and
I
like
worked
on
rails
for
a
long
period
of
time,
and
the
number
one
thing
that
was
super
bug
me
is
bug
reports
that
were
filed
the
day
after
the
release
like
we
would
do
like
hey
everyone,
here's
a
release
candidate.
A
If
we
don't
see
any
bugs
in
two
weeks,
we
will
cut
a
final
and
then
we'd
like
get
one
or
two
reports,
and
we
do
it
again
and
say:
here's
the
next
one
you
know
whatever
and
then
it
would
never
fail
the
same
day.
We
would
release
the
final
we'd
get
like
10
bug.
Reports
of
like
this
is
totally
broken
on
my
machine
like
why?
A
Couldn't
you
just
told
me,
like
literally
yesterday,
like
please
just
run
the
release
candidate,
so
I
hope
that
some
of
you
get
intrigued
by
rust
and
come
and
help
use
it
to
point
out
any
blind
spots
that
we,
as
a
team
have
about
making
rest
happen?
Okay,
so
some
code-
I
also,
I
should
say
we
as
far
as
rust
team
goes,
I'm
not
employed
by
mozilla.
I
work
for
a
company
called
balance.
A
So
I
can
write
documentation
from
the
perspective
of
a
newbie
all
the
time,
which
is
growing
more
and
more,
not
true,
but
that's
sort
of
my
like
self-appointed
role
and
I've
written
a
significant
amount
of
the
documentation
for
rest
stuff,
so
I'm
on
the
team,
but
not
employed,
okay,
so
some
code.
Now
we
got
all
that
meta
stuff
out
of
the
way,
that's
actually
like
show
what
rest
is
before
I
want
to
talk
about
rust,
though
I
want
to
show
you
some
C
code.
A
So
here
is
like
what
the
most
compelling
aspect
of
rust
to
me
is:
what's
the
matter
with
this
C
code,
so
yeah
there's
a
little
small.
Let
me
try
this
plus
thing
again.
Well
that
made
it
a
little
bit.
It
makes
the
arrows
big
and
not
the
code
whatever
okay,
so
this
is
int
main
void.
Char,
star
s
equals
hello,
world
astra
guess
equals
H,
so
this
C
code
will
completely
compile
I,
believe
I'm,
modern
compilers.
A
It
will
give
you
a
warning
when
you
compile
it
saying:
hey
you're,
doing
something
stupid,
but
the
c
compiler
will
happily
turn
this
into
assembly
code
and
when
you
run
it,
it
will
seg
fault,
and
I
think
I
have
the
seg
fault
error
message.
This
is
actually
the
rest
one
so
wow
that
big
arrow
makes
it
much
slower
to
transition.
A
So
this
will
seg
fault,
because
s
is
actually
know
a
statically
allocated
string
and
you
can't
change
stuff
and
you
like,
when
you
try
to
modify
it,
it
will
blow
up
basically
so
in
rust,
if
you
wrote
the
equivalent
code-
and
this
top
is
what
some
like
rust
code,
look
like
FN
main
break,
brit
parenthesis
and
a
bracket,
let
s
equals
ampersand
hello
world
and
then
dereference
s
to
try
to
change
it.
H.
Rust
will
actually
give
you
a
compile-time
error
that
says
error.
A
They
type
a
10-percent
string
cannot
be
dereferenced,
and
this
this
type
cannot
be
dereferenced,
because
if
it
is
dereference,
then
it
would
cause
a
segfault.
So
rust
is
able
to
tell
you
at
compile
time.
This
is
a
problem
now,
as
I
mentioned,
modern
compilers
will
give
you
kind
of
a
warning,
but
this
is
sort
of
the
setup
for
everything
else
about
rust.
A
It
does
a
lot
of
work
up
front
to
guarantee
things
that
would
be
errors
and
other
low-level
languages
are
actually
caught,
and
this
example
is
a
trivial
one,
because
their
slides
and
I
want
to
like
ease
you
into
this
idea.
But
there
are
significantly
more
complicated
things
that
are
legal
technically
according
to
the
specs,
but
will
give
you
failures
when
you,
your
code
actually
runs,
and
so
this
is
like
what
rust
is
really
good.
At
is
saying.
No,
that
doesn't
compile.
A
I
was
a
haskell
user
for
a
little
while
and
Haskell
people
always
say
that,
like
once
you're
Haskell
code
compiles,
it
works
without
bugs
and
that's
not
totally
true
and
rust.
But
it's
pretty
damn
true
in
many
instances
that,
like
your,
you
will
spend
a
lot
of
time
fighting
the
compiler,
but
the
compiler
is
actually
telling
you
your
code
is
actually
wrong
and
once
you
fix
those
problems
like
you're
good,
just
super
different
coming
from
Ruby
unit
testing
like
Ruby,
let
you
do
anything
you
want.
A
Okay,
so
here
is
actual
hello
world
and
I
decided
to
import
the
println
for
fun.
So
rust
has
an
actual
real
module
system,
so
you
can
say,
use
standard,
I/o
and
then
import
just
the
println
function
from
the
standard.
I/O
module
it'll
only
bring
println
in
the
scope
and
then
FM
main
println,
hello
world's
this
looks
relatively
similar
and
the
syntax
of
rust.
A
Generally
speaking
is
trying
to
be
familiar
to
people
who
have
used
systems
level,
curly
brace
languages
in
the
past,
so
this
is
like
very
close
to
what
the
C
or
C++
would
be.
So
if
we
got
the
FN
in
there
and
you
don't
need
to
define
the
arguments
domain,
if
you
don't
want
to
here's
something,
a
little
more
complex,
so
let
numbs
equal
one
and
to
let
noms
Eagle,
Tim,
East
and
Aaron
and
Ben,
and
then
let
mute
odds,
equal
numsa
da
map
x
times,
2
minus
14,
num
and
odds
spawn
proc
println
some
stuff.
A
So
this
adds
a
whole
bunch
of
other
interesting
things
about
rust,
so
first
thing
to
notice
at
the
very
first
line
variables.
So
in
rust
you
define
variables
using
the
let
keywords
you
say:
let
numbs
equals
and
that
actually
says
what
it
is.
And
then
this
is
a
rust
calls.
Arrays
vectors.
This
is
a
vector
of
two
integers
rust
actually
does
full
Hindley
Milner
type
inference.
So
this
is
actually
even
though
we've
not
written
any
type
signatures.
Rust
knows
that
noms
are
numbs,
is
a
vector
of
type
int
like
it
can
infer
that
automatically.
A
A
The
third
line
is
super
interesting,
and
one
of
the
reasons
why
I
think
rust
is
really
neat
and
is
that
rust
has
stolen
a
lot
of
really
high
level
concepts
from
languages
like
ml
and
Haskell
and
even
Ruby,
and
then
brings
them
down
in
this
like
performance
systems
way.
So
this
says
numbs
it
er,
which
generates
an
iterator
out
of
the
numbs
array
and
then
calls
map
on
it.
A
If
you're
not
familiar
with
map
from
various
functional
languages,
map
is
basically
a
function
that
takes
another
function
and
then
applies
that
function
to
every
element
of
the
list.
So
this
function
it
takes
one
argument,
X
news,
VA
pointer,
and
then
it
will
take
the
value
of
x
times,
2
minus
1.
So
this
will
give
you
an
iterator
that
returns
the
odd
numbers
in
the
list.
In
this
case
there's
only
one.
If
you
had
more
of
them,
there
would
be
more
obviously
a
publisher
to
made
it
one
two,
three,
four
five,
whatever
the
other
thing.
A
That's
interesting
about
this
is
it
says,
let
mute
odds
so
in
rust.
Variables
are
immutable
by
default
and
you
can
add
mutability
by
adding
the
mute
keyword
on
to
it.
This
is
generally
considered
to
be
wise
advice
from
most
people
that,
like
mutable
state,
is
usually
bad.
You
want
to
try
to
be
immutable
as
much
as
possible,
so
I
decided
to
make
this
iterator
mutable
to
show
that
off
I,
don't
think
it's
actually
strictly
necessary.
We
don't
use
the
mutability
and
rust
will
actually
give
you
a
warning
and
say:
hey.
A
You
made
this
immutable,
but
you
don't
ever
actually
mutate
it.
So
you
should
think
about
removing
the
mute,
then
a
for
loop.
So
you
know
the
good
old
flash
in
C++
for
loop
with
like
the
three
sections
where
you
start
off
at
zero
and
you
have
an
increment
and
it's
all
complicated
that'll
goes
away
and
rust
actually
gives
you
these,
like
the
more
standard,
modern
iterator
style
for
loops,
but
it
compiles
down
of
the
same
stuff
that
the
original
for
loop
would
have.
A
If
that
doesn't
mean
anything
to
you,
don't
worry
about
it.
Basically,
it
just
means
that
they're
safe
to
pass
around
between
tasks,
so
we're
Russ
can
actually
implement
task,
steal,
a
work,
stealing
task
scheduler
for
threading
stuff
because
they
are
all
I,
completely
isolated
and
then
inside
this
we
use
println
bang,
which
is
a
macro
rust,
has
hygienic
macros
instead
of
a
see
press
instead
of
a
process
preprocessor
like
C++
or
C.
A
Rather,
I
should
say
that
does
textual
substitution,
rust
macros
actually
operate
on
a
st
just
super
cool
and
they
give
us
these
formatting
strings
which
are
not
printf
floor
matting
strings
but
are
like
I.
Think
Python
supports
the
syntax
one
or
two
other
things,
so
the
brace,
kool
&,
S
brace,
gives
you
substitute,
noms
numb,
and
then
you
can
access.
You
know
the
first
element
or
second,
I
guess
this
is
number
one
of
the
noms
array
and
it
will
print
out.
A
Eston,
says
hello
from
a
lightweight
thread,
so
this
is
like
the
way
it
looks.
It's
like
kind
of
familiar
low-level
stuff
with
this
high
level
stuff
into
it,
and
the
thing
that's
interesting
about
this
is
that
it's
chosen
in
a
way
that
it
costs
are
always
explicit.
So
I
mentioned
this,
the
spawn
syntax
had
changed.
It
used
to
be
do
spawn
curly,
brace.
A
The
problem
with
that
is
people
wanted
to
make
sure
that
you
knew
you
were
actually
going
to
be
allocating
a
closure
and
that
kind
of
hid
that
you
were
allocating
a
closure,
and
so
they
decided
to
make
it
explicit
and
so
in
some
like
in
generally
rust
will
always
try
to
make
costs
explicit
to
you
so
anyway.
That's
that
so
references
rust
has
two
kinds
of
pointers
that
are
built
into
the
language.
A
This
is
a
dumb
use
of
references,
because
an
integer
is
an
injury
sci,
so
you
wouldn't
make
a
pointer
to
an
integer,
but
because
it's
a
slide
illustration
I
just
wanted
to
show
you.
This
is
like
how
it
works.
This
also
gives
you
the
syntax
for
defining
functions.
You
can
that
it's
like
identify
or
colon
type
and
then
there's
an
arrow
with
a
return
type
on
the
end
for
function,
definitions,
and
this
will
take
a
reference
to
that
five.
Send
it
to
the
function.
It
will
do
its
stuff
and
you'll
get
six
pack.
A
The
other
kind
of
pointer
that
is
built
into
the
language
technically
doesn't
need
to
be
built
into
the
language
can
be
implemented
as
a
library,
but
it's
so
useful
that
we
gave
it
special
language
syntax
and
that
we
call
these
boxes.
You
may
have
heard
them
referred
to
as
owned
pointers
previously,
but
this
now
we
declare
let
x
equals
tilde
5
and
that's
a
box
25.
The
difference
to
this
is
that
in
this
version
you
are
sending
a
reference
to
a
value
on
the
heat
on
the
stack
on
like
five.
A
The
integer
is
like
stack
allocated.
This
five
will
actually
be
heap
allocated,
so
this
is
a
reference
to
something
on
the
heap
if
you're
a
C++
developer.
This
is
very
similar
to
the
unique
pointer
in
boost,
but
is
it
the
language
level,
so
you
can
make
stronger
guarantees,
so
the
unique
pointer
is
not
actually
truly
memory
safe,
whereas
this
actually
is,
and
so
this
will
send
in
the
value
of
x
into
+1
and
using
a
reference
and
the
type
function.
A
Signature
doesn't
change
because
you're
just
taking
a
reference
to
what
already
exists,
you
can
pass
in
either
kind
of
pointer
that
you
want
and
that's
a
box.
So
what's
cool
about.
This
is
another
thing:
I
love
about
rust.
So
if
I
was
doing
this
in
C,
I
would
need
to
be
doing
like
Malik
the
size
of
an
integer
right
and
I
need
to
be
keeping
track
of
where
X
goes
out
of
scope
and
I
need
to
call
free
on
it.
So
what
rust
kind
of
does
is
rust,
says:
hey
a
compile-time.
A
We
know
that
this
is
a
pointer
to
an
integer.
We
know
where
the
variables
in
scope,
so
rather
than
making
you
the
programer,
do
this
chore
of
figuring
out
the
amount
of
memory
allocating
it
d,
allocating
it
rust,
essentially
inserts
a
Mallick
before
this
comes
in
a
scope
and
a
free
after
it
comes
out
of
scope
and
gives
it
the
appropriate
size,
because
it
knows
all
that
stuff
a
compile-time.
So
that's
super
cool
and
one
example
of
like
reducing
human
errors
by
allowing
the
compiler
to
actually
give
you
correct
code
instead.
A
So
this
has
no
performance
penalty
over
malloc
and
free.
It's
basically
the
same
thing
at
the
assembly
level.
So
that's
super
cool
asks.
So
I
showed
you
that
spawn
proc
shenanigans
before
to
talk
about
spinning
up
a
task
which
is
a
thread
basically
a
lightweight
thread,
but
they're
totally
isolated
from
one
another.
So
you
can
actually
use
channels
to
communicate
between
tasks.
So
this
is
a
function
that
gives
you
a
channel
and
a
port.
A
So
this
is
ad
sugar
or
D
structuring,
let
assignment
so
you
can
actually,
if
you're,
the
channel
returns
both
ends
of
the
channel
that
you're
making
and
it
assigns
them
to
each
variables.
This
is
signing
two
variables
in
one
line.
Basically,
and
then
we
spin
up
a
procedure
and
we
say,
result
equals
five
and
then
send
the
result
down
the
channel
and
then
in
the
main
function
again,
we
say,
result
equals
point
our
port
receive
and
then
we
print
out
the
results.
A
Now
you
may
be
wondering
how
the
channel
actually
gets
into
the
procedure
there
that's
being
spawned
and
basically
rust.
Will
it
knows
that
you're
using
that
channel
inside
of
the
procedure
and
therefore
automatically
transfers
ownership
over
to
it?
So
I'll
show
you
example
where
this
actually
fails
in
the
next
slide.
So
if
I
was
going
to
be
sending
a
value
of
five
down
the
channel,
this
would
also
work.
A
So
it's
like
dereferences
this
value
of
five,
and
it
knows
that
the
channel
that
the
task
is
using
X
and
it's
using
the
channel,
so
it
sort
of
gives
them
to
it,
but
then
those
become
invalid
in
the
extra
scope.
So
if
we
tried
to
use
X
after
we
spawned
that
procedure
like
in
this
case,
dereferencing
X
and
adding
one
to
the
value
which
is
wrong
for
two
different
reasons-
we'll
get
two
different
compiler
errors.
A
The
first
one
is
error:
use
of
moved
value,
X
note
ex
moved
into
a
closure
environment
because
it
has
this
appropriate
type
which
is
non
copyable.
Perhaps
you
meant
to
use
clone,
and
so
this
is
saying:
hey
your
closure.
Your
procedure
is
already
using
the
value
of
x.
It
could
be
mutating
X.
It
could
be
doing
whatever
to
X
that
reference
is
no
longer
valid,
and
so
rust
will
actually
at
compile
time,
prevent
you
from
sending
mutable
state
over
concurrency
boundary,
which
is
like
super
mind-blowing
ly.
A
Amazing,
if
you've
ever
had
to
debug
concurrency
issues
around
mutable
state
and
the
other
thing
is
well
give
you
an
error,
cannot
assign
to
e
mutable
dereference
of
the
pointer
because,
like
X,
is
immutable
and
I
try
to
add
one
to
it.
So
it's
wrong
in
two
different
ways,
but
this
is
an
example
of
rust,
giving
these
like
really
strong
guarantees
about
mutability
and
about
safety,
which
is
super
super
cool
pattern
matching.
A
This
is
an
example
of
something
that
comes
from
the
functional
world
that
rust
is
implemented
in
a
way
that
basically
boils
down
to
a
case
statement,
but
is
much
more
powerful.
You
can
say
match
and
then
some
sort
of
expression
and
then
give
it
arbitrary
like
arms,
they
call
them
matching
arms.
So
if
this
number
is
zero,
it
will
print
zero
if
it's
one
or
two
or
print
one
or
two.
A
If
it's
from
the
range
of
three
to
ten,
it
will
print
three
to
ten
and
then,
if
it's
anything
else,
the
underscore
basically
just
means
ignore
it
print
something
else.
This
is
cool
because,
first
of
all,
we
can
come
up
with
relatively
complicated.
Expressions
of
the
excuse
me
on
the
left
hand,
side
of
this
to
actually
match
against,
but
the
most
interesting
part
is
the
last
part.
I
forget.
If
I
have
an
error
message
here,
I
don't
so
I'll.
A
Just
tell
you
what
it
is
if
I
had
left
out
that
underscore
whatever
Russ
would
give
me
a
compile-time
error,
saying
non-exhaustive
match
statement.
So
rust
actually
knows
that
you
need
to
be
able
to
you're
passing
in
an
integer
type
and
therefore
you
should
handle
every
possible
integer
that
comes
in
and
if
you
don't
handle
all
the
cases,
it
will
give
you
an
error.
That's
why
we
need
this
bottom
to
sort
of
say
any
other
integer
we
don't
care
about,
and
this
is
cool
because
usually
what
happens
is
if
you're
not
handling
a
case?
A
That's
an
instance
a
possibility
for
a
problem
of
some
kind.
So
to
sort
of
bump
this
up
a
notch.
Russ
has
option
types
which,
if
you've
used
something
like
Haskell
you're
familiar
with,
so
we're
saying,
let
message
equals
sum
and
then
a
string
howdy,
a
reference
to
a
string,
a
stack
heap
allocated,
string,
howdy
and
some
is
a
type
in
rust
called
option.
So
option
basically
is
made
up
of
two
subtypes
some
and
none,
and
what
that
means
is.
If
it's,
some,
a
computation
is
succeeded,
and
if
it's
none,
it
is
failed.
A
So
what
we
can
do
is
we
can
say,
match
message
and
if
it's
some
em
printed
out.
Otherwise,
if
it's
none
do
nothing.
So
this
is
very,
very
similar
to
null
pointers
if
you're
familiar
with
null
pointers
at
all
rust
does
not
have
the
concept
of
null
basically
in
the
language
at
all.
The
guy
who
invented
null
calls
it.
My
billion
dollar
mistake
null
pointer,
dereferences
have
caused
many
a
security
issue,
and
so
rust
does
not
allow
you
to
have
things
that
are
no.
A
It
does
how
you
allow
you
to
use
this
sum,
none
along
with
match
to
sort
of
emulate
a
null
value,
but
in
a
way
that
is
checked
at
compile
time.
So
it's
impossible
to
dereference
a
null
thing,
because
you
get
this
none
back
and
you
have
to
handle
it
in
some
fashion
and
you
can't
forget
to
do
it
because
it
will.
If
you
try
to
use
message
without
using
this
match
to
like
fetch
stuff
out
of
it,
then
you
would,
it
would
be
the
wrong
type.
A
It
would
be
some
string
instead
of
a
string-
and
this
happens
often
when
you're
like
so
in
this
case
it's
trivial.
We
can
see
it's
obviously
going
to
succeed,
but
if
you
imagine
a
message
was,
for
example,
reading
from
a
file
right,
you
may
get
a
string
back,
you
may
not
get
a
string
back,
it
depends
so
option
types
are
super
cool
closures.
I've
already
mentioned
are
like
a
first-class
concept,
so
you
can
actually
define
a
variable
square.
That
is
a
closure
that
takes
one
argument
of
X.
A
So
it's
an
integer
and
returns
a
you
int
back
and
basically
does
x
times
X
as
you
int,
since
it
should
always
be
positive,
you
want
to
cast
it
to
a
positive
integer
and
then
you
know
let
max
equal
0,
1,
2,
3
dot
map
and
then
pass
in
a
closure.
That's
you
know
Anonymous
in
this
case,
instead
of
named
and
do
all
your
normal
stuff
here,
and
so
this
actually
is
like
pretty
efficient,
because
it's
a
language
level
feature.
A
A
Generics
rust
has
generics
woohoo
generics
are
amazing
and
wonderful.
They
kind
of
look
a
little
scary.
This
is
one
of
the
downsides
of
using
a
strongly
strongly
typed
language
is
at
first,
the
type
signatures
can
get
pretty
intense,
so
this
is
actually
a
relatively
simple.
This
is
the
definition
of
map
from
up
here,
applying
this
closure
to
every
single
element
of
the
array,
but
it
uses
generics.
A
The
more
you
read
it
and
we
argued
about
the
syntax
a
lot,
and
this
is
one
of
the
more
complicated
type
signors
I
should
possibly
show
you
I
shouldn't
say
possibly
but
like
this
is
a
higher
than
average
complexity
type
signature,
because
this
is
a
library
function
that
would
be
written
by
a
library
author.
You
would
generally
like
write
this
yourself,
but
I
wanted
to
show
you
that,
like
it
can
get
complicated
and
that's
a
downside
of
using
a
strongly
typed
language.
A
This
is
like
why
people
don't
use
Scala
right
is
cuz
scala's
like
type
signatures
are
like
super,
intense
and
ridiculous.
It
happens,
but
this
will
generically
operate
over
any
type.
T
or
you
and
what's
cool
about
it
is
rust,
actually
doesn't
mono.
Morph
is
a
shin,
so
this
is
not
actually
dynamically
dispatched.
When
you
use
this
map
function
it
will,
it
will
statically
determinate.
I
piĆ¹
ever
call
map
on
and
then
generally
specialized
versions
of
this
functions
that
operate
natively
on
those
types
and
statically
dispatch.
A
So
it
is
the
same
speed
as
if
you
hand-wrote
a
custom
map
type
for
every
single
type.
You
use
map
for,
or
you
don't
have
to
do
it
yourself,
which
is
awesome,
struts
and
traits
so
rust
has
struck
switch
work
just
like
cease
trucks
down
to
the
way
they're
represented
in
memory,
which
is
super
useful
for
FF
I'll
talk
about
in
a
little
bit.
This
is
a
time
bomb
struck
for
the
explicit
iffat
EU
int
value
you
can
put
whatever
value
want
in
there.
But
rust
has
this
interesting
system
called
traits.
A
Rust
does
not
directly
support
object-oriented
programming
directly,
but
it
has
this
trait
system,
which
is
neat.
So
what
we
can
do
is
we
can
say,
I
want
an
implementation
of
a
trait
name
drop
for
the
time
bomb.
Struct
and
rust
uses
the
drop
trait
to
implement
destructors.
Basically,
so
what
I'm
doing
is
I'm
defining
a
destructor
for
time
bomb
by
defining
this
drop
trait
the
dropped
rate,
mandates
that
I
write
a
drop
function?
A
That
does
something
so
in
this
case,
whenever
my
time
bomb
goes
out
of
scope,
it
will
print
blam
n
times,
where
n
is
the
explosive
ax
t
value
that
is
stored
in
the
struct
and
a
lot
of
rusts
features
like
language
level
features
are
implemented
via
this
trait
system.
So,
for
example,
constructor
is
normally
a
language
level
feature
or
technically
a
library
level
feature
where,
when
the
variable
goes
on
a
scope,
it
calls
this
function
on
it.
A
A
You
can
also
define
traits
on
any
type
at
all,
so
you
can
define
and
trait
on
an
int,
and
that
will
be
totally
fine
and
that
gets
super.
Intense
traits
can
also
be
parameterised
in
the
same
way
that
you
know
you
saw
generics
earlier.
This
is
a
sequence
trait.
This
is
what
a
trait
definition
looks
like.
A
As
I
said,
you
can
technically
implant--
traits
on
int,
so
you
who
to
caps
of
ruby
and
then
ember
fame,
decided
to
try
to
port
active
support
to
rust.
Just
to
see
what
would
happen.
This
is
not
a
good
example.
You
should
never
use
code
like
this.
This
is
bad,
but
it's
cool,
so
you
can
say
let
time
equals
time
now
and
then
println
time
and
then
for
Dylan,
two
days
dot
from
now
and
this
works
and
it
actually
works
the
same
as
if
you
had
written
the
functions
to
call
it.
A
It
just
looks
like
object,
oriented
e
again,
it's
all
statically,
dispatched
and
technically
only
integers
within
the
area
that
says
use
active
support
period
and
use
active
support.
Time
get
these
patches,
so
another
library
you're
never
going
to
have
the
problem
like
in
Ruby.
If
you
do,
this
integer
forever
has
days
on
it
as
a
method,
and
it
causes
lots
of
problems.
This
is
only
in
the
scope
that
you
actually
made
the
use,
so
other
modules
will
not
be
affected
by
this.
It's
only
your
code,
which
is
kind
of
neat
but
yeah.
A
A
Ruby,
which
allows
me
to
express
things,
the
high
level,
and
so
with
rusts
trait
system,
combined
with
it's
like
high
level
map
and
filter
features
and
like
the
closure
stuff,
it
feels
a
lot
like
a
higher-level
language,
even
though
it
is
truly
super
low
level.
This
is
another
example
of
implementing
traits
I'm
not
going
to
bother
going
through
all
of
it,
but
you
can
just
like
see
that
a
period
trait
this
is
how
the
thing
works
and
active
support.
A
Is
that,
like
the
two
dots
seconds
returns
a
time
change
object
and
then,
on
the
time
James
altona
object,
that's
struct
and
the
time
to
change.
Struct
has
another
trait
implemented
on
it.
That,
like
makes
all
those
things
happen.
So
if
you
screwed
it
up,
we
compile
time
error
on
ffi
is
another
awesome
thing
about
rust.
Rust
has
an
amazing
fi
system,
so
you
can
call
in
to
see
code.
However,
you
want,
which
is
really
great.
A
It's
been
helpful
to
bootstrap
a
lot
of
the
ecosystem,
because
we
could
wrap
see
libraries
instead
of
we
pullin
in
our
own.
For
example,
it
has
been
decreed
that
there
will
be
no
official
reimplement
ation
of
crypto
libraries
in
rust
itself.
We
will
link
to
see
ones
because
people
have
actually
written
that
code
and
audited
it,
and
we
don't
want
to
screw
anything
up,
and
we
want
to
be
very
careful
about
crypto
so
bindings
to
lib
SSL
or
whatever
else
it
is
open
SSL.
A
So
this
also
has
one
other
interesting
feature
of
rust:
I
don't
talk
about
which
is
unsafe.
So
here's
the
thing
all
of
this
like
discipline,
the
rust
compiler
makes
sure
that
everything
works,
for
you
is
really
nice,
but
sometimes
you
are
smarter
than
the
compiler
and
so
rust
gives
you
the
ability
to
say
unsafe
in
a
curly
brace
and
a
closed
curly
brace
and
then
that
restrict
that
lifts
a
lot
of
the
restrictions
not
all
of
them,
but
a
lot
of
the
restrictions
around
dangerous
operations.
A
So,
for
example,
inside
of
an
unsafe
block,
you
can
do
arbitrary,
pointer,
arithmetic
but
outside
of
an
unsafe
block.
That
is
impossible
and
the
reason
is
because
rust
is
ultimately
a
pragmatist
language,
and
so
we
understand
that
sometimes
you
will
need
to
write
code
where
you,
the
human,
verifies
that
it's
safe
for
performance
reasons
or
like
what
other
other
reasons.
So,
for
example,
in
FF
I
would
not
work
because
the
C
code
does
not
provide
the
appropriate
guarantees
through
to
rust,
like
when
you're
calling
it
an
arbitrary
C
code.
A
A
So
you
basically
get
like
static
analysis
to
make
sure
you
haven't
done
anything
dangerous
on
most
of
your
code,
if
you've
ever
tried
to
like
solve
a
dangling
pointer
problem
and
a
large
C++
code
base,
you
love
and
no
Val
grind
and
it
like
kind
of
works.
But
you
know
like
cross
your
fingers
and
you're
like
a
detective
with
rust.
You
have
very,
very
small
amounts
of
unsafe
blocks.
You
can
audit
those
areas
and
it's
much
much
easier
to
figure
it
out.
A
So
in
this
case,
I'm
I'm,
linking
to
an
external
library
called
snappy,
which
is
like
a
gzip
library
and
I'm.
Saying
I
expect
this
extern
symbol
snappy
max
compressed
length-
and
this
is
basically
just
a
copy
of
the
header
file,
but
in
rust,
syntax,
as
opposed
to
C,
syntax
and
I,
had
to
import
lib
sees
size,
t
type
to
make
it
happen,
and
then
in
Maine
I
call
unsafe,
snapping
back
to
compress
the
length
of
one
hundred
and
it
will
print
out
the
results.
A
And
so
this
just
calls
nough
see
and
its
really
trivial
and
it's
awesome
now
that
would
be
a
pretty
poor.
Rapper
like
you
would
never
use
the
lot
C
library
this
way.
The
idea
would
be
that
you
would
move
the
unsafe
code
into
a
safe
rust
code
and
you
would
expose
a
natural
rust
wrapper
on
top
of
your
unsafe
stuff,
and
so
this
is
much
more
common
and
so
you're,
essentially
promising
the
invariants
that
the
rust
compiler
would
do
to
your
code
above
it.
And
then
this
is
like
the
way
that
really
happen
is
like.
A
This
is
an
uncompressed
function
that
uses
that
snappy
uncompressed
length,
but
does
a
whole
bunch
of
other
stuff
with
like
pointer,
rithmetic
and
like
vector
capacity,
stuff
and
mutating
things
that,
like
would
not
really
be
allowed
otherwise
and
returns
a
some
compressed
thing
or
a
nun
if
there's
a
fail,
and
so
this
is
an
example
of
like
a
real
rapper
around
a
C
library,
it
doesn't
really
matter
what
it
does.
I'm
just
rying
to
show
you
some
syntax.
A
You
can
sort
of
see
what
it
looks
like
vaguely,
but
it's
really
convenient
to
work
with
C
code,
and
that
means
that
there's
a
lot
of
really
nice
things
about
it,
but
that
works
because
you
can
totally
drop
into
super
low
level.
You
know
whatever
you
want
people,
multiple
people
have
started
writing
operating
systems
in
rust.
A
There's
an
amazing
blog,
I,
really
really
love
Bourque
with
a
zero
julia
evans,
I
believe,
is
her
actual
name
has
been
writing
this
blog
series
about
making
an
operating
system
in
rust,
and
it
is
the
most
wonderful
piece
of
like
classic
hacker
programmer.
I
have
no
idea
what
I'm
doing,
but
this
is
so
amazing
and
like
joyful,
it's
like
my
favorite
he's
like
15
or
20
posts
she
wrote
about.
It
is
like
hey
today,
pressing
a
key
on
my
keyboard.
A
Doesn't
crash,
might
crash
my
machine
anymore,
like
I'm,
making
progress
and
its
really
great
but
she'd
bring.
She
explains
how
she's
actually
building
an
operating
system
from
nothing
in
rust
and
it's
super
cool,
and
you
should
check
it
out
if
you
like,
mega
low
level
stuff.
Okay,
so
hopefully
I've.
Given
you
a
little
bit
of
taste
of
what
makes
rust
cool
like
concurrency
stuff
is
super
awesome
v
like
safety,
the
compiler
gives
you
is
great.
You
don't
have
to
do
as
much
housekeeping
like
everything
is
really
awesome
about
rust.
A
But
if
you
want
to
learn
more,
obviously
you're,
not
you
know
you
probably
vaguely
even
understand
what's
going
on
at
this
point,
because
I
just
showed
you
a
bunch
of
syntax.
So
later,
hopefully
you'll
go
check
it
out.
Here
are
some
things
you
can
do
to
learn
more
about
rest.
So
there
are
a
bunch
of
really
great
projects
that
people
have
written
in
rust.
A
That
can
give
you
an
example
of
like
what
a
real
program
looks
like
so,
for
example,
rust
boot
is
a
project
that
brings
up
from
it's
the
assembly
shim
that
goes
from
a
32-bit
computer
to
a
rust,
like
k
main
basically
like
that
when
you're
writing
actual
kernel
code
and
rust,
that
was
the
precursor
project
to
the
one
I
was
just
telling
you
about
that.
Julia
wrote,
there's
rust
HTTP,
which
is
an
HTTP
library
that
is
written
in
rust.
A
That's
super
neat
they're,
actually
experiment
with
using
typed
header
values,
so
it
can
like
tell
you
if
it's
an
experimental
header
or
a
standardized
header
things
like
that
rust
core
is
a
rust
that
without
any
of
the
standard
library,
so
you
could
use
it
on
embedded
devices.
There's
some
people
doing
cool
stuff
with
that
sprocket
nes
is
a
nintendo
emulator,
written
and
rust
that
can
play
mario,
just
super
cool,
rusty,
mem
russ,
Redis
trust
message:
pack,
our
native
russ
tree
implementations
of
the
Redis
and
memcached
protocols.
A
So
you
got
like
real
wrappers
for
those
things
and
angle,
mwah
I!
Think
it's
how
you
say
it
because
who
knows
rust.
Is
this
game?
It's
like
beatmania,
if
you're
like
ddr
but
written
in
rust.
So
it's
a
full
video
game.
It's
like
eight
or
nine
thousand
lines
of
rust.
That's
like
super
cool
too,
as
an
example,
so
you
can
check
out
those
like
real
world
projects.
A
The
other
thing
I
forgot
entirely
with
servo
I
have
three
minutes
so
I
can
hurry
up
and
say
this
the
thing.
The
other
thing
that
so
rust
is
implemented
in
rust.
It's
one
of
the
largest
rust
code
bases,
the
second
largest
rust
code
base
is
servo.
Servo
is
a
browser
rendering
engine
that
Mozilla
is
writing
in
r
us
to
build
a
next-generation,
massively
parallel,
completely
safe
rendering
engine
so
that,
hopefully
they
don't
get
pwned
to
owned
in
the
future
by
gecko
stuff.
A
So
it
is
like
150
thousand
lines
of
rust
or
whatever,
and
the
rust
language
takes
lessons
used
from
building
servo
a
real-world
application
in
the
language
itself,
so
they
feed
back
into
each
other.
So
servo
will
try
out
a
new
feature,
no
se,
actually
that's
terrible
and
then
it'll
get
removed
from
the
compiler
and
then
like.
Oh,
we
actually
do
need
this
other
thing
and
you'll
get
added
and
that's
been.
A
One
of
the
big
drivers
of
making
rest
of
practical
language
is
because
it
has
itself
and
also
a
major
component
that
is
being
written
in
it
to
help
drive
it
in
a
practical
way.
As
far
as
other
introductions
rust,
there
is
an
official
tutorial
which
is
terrible,
they're
paying
someone
currently
to
rewrite
it,
but
has
not
yet
been
rewritten.
So
it's
been
cobbled
together
by
systems
programmers
over
the
last
six
years,
and
you
know
they're
amazing,
at
low-level
programming
and
terrible
at
writing.
A
Writing
it
to
help
them
with
it,
and
it's
also
a
rest,
tutorials
ng
project,
they're
a
bunch
place
to
discuss
rusts
there's
a
rust
dev
mailing
list
of
Mozilla
runs
there's
a
subreddit
which
I
hate
read
it,
but
the
rus
sub
read
is
ok.
There's
an
mozilla
chat,
room
on
IRC
talk,
mozilla,
org
and
there's
a
really
great
blog
post
series
written
by
CM
are
called
this
week
and
rust.
That
gives
you
a
summary
of
what
has
gone
on
in
last
week.
A
It's
often
a
new
way
to
like
check
out
what
cool
stuff
has
been
happening
in
rust
world
and
then,
finally,
you
can
check
out
the
actual
code
to
rust
at
github
com,
/,
Mozilla,
/,
rust
and
rush
rusty.
Langberg
is
the
official
website,
although
I
forever
linked
to
it
on
here.
So
with
that,
I
am
exactly
a
time
give
or
take
30
seconds.
I
guess
so.