►
From YouTube: Rust Linz, Interlude - A Love Letter To Rust
Description
Together with heise developer, the Rust Linz meetup gives a small tour on what's to like about the Rust programming language
A
Much
thank
you
for
the
possibility
to
do
this
talk
to
spend
one
hour
with
a
love
letter
to
rust.
This
is
what
you
can
expect.
You
can
expect
three
quarter
an
hour
with
a
lot
of
colds,
taking
a
look
why
rust
is
attractive.
This
is
exactly
the
talk
if
you're
curious,
what
this
rust
is
all
about,
and
why
so
many
people
are
eager
to
learn
this
new
programming
language.
A
Before
I
go
into
the
topic,
I
would
like
to
introduce
myself
for
those
of
you
who
do
not
know
me.
My
name
is
reina
stropak
and
I'm
broadcasting
here
from
a
city
called
leonding.
This
is
a
city
near
lynds,
I'm
a
passionate
programmer
for
more
than
25
years.
Now,
I'm
also
a
microsoft,
mvp
and
regional
director,
but
that
does
not
mean
that
I'm
on
the
payroll
of
microsoft,
but
I
do
a
lot
of
work
in
the
microsoft
area,
especially
in
the
context
of
the
microsoft
azure
cloud.
A
Technica
professionally,
I
am
a
trainer.
I
am
also
a
part-time
teacher
and
I'm
a
mentor
at
the
local
coda
dojo,
and
that
brings
me
to
the
last
thing
which
is
really
near
to
my
heart,
and
that
is
community.
I
love
community
work,
I'm
the
chairman
of
the
coding
club
lintz,
and
we
run
our
local
coda
dojo,
which
is
a
programming
club
for
kids.
No,
we
do
not
program
rust
there.
My
rust
life
in
terms
of
community
is
the
rust
lintz
meetup
and
you
are
very
much
invited
to
join
us
for
one
of
our
upcoming
meetups.
A
We
do
monthly
meetups,
where
you
can
hear
talks
from
speakers
all
over
the
world
and
exchange
your
ideas
problem
thoughts
whatever
regarding
rust
in
our
discord
server.
Now
what
is
my
talk
today
about
you
see?
I
think
that
choosing
a
programming
language
is
a
little
bit
like
entering
a
relationship.
A
If
you
are
a
professional
programmer
like
I
am
you
spend
a
lot
of
time
with
with
the
language
you
spend
this
this
language,
this
relationship
should
be
a
kind
of
loving
and
caring
relationship.
It's
don't
get
me
wrong.
This
is
not
the
kind
of
love
that
I
feel
for
my
spouse
or
my
god
child,
but
still
it
is
a
kind
of
love.
I
have
to
be
passionate
about
the
programming
language
that
I
work
with.
A
The
first
question
that
we
have
to
speak
about
is:
why
is
rust
so
attractive
for
many
developers
think
about
how
a
relationship
starts.
You
meet
someone
and
you
feel
attraction
again.
It's
similar
with
programming
languages.
If
you
are
new
to
rust,
you
might
ask
yourself.
Why
should
I?
Why
should
I?
Why
should
I
invest
time?
Why
should
I
invest
money
for
for
books,
maybe
for
trainings,
and
things
like
that?
Does
it
have
a
future
before
we
go
into
the
technical
details?
Let's
discuss
this
question
for
a
few
minutes.
A
A
Let's
dive
a
little
bit
deeper
into
that
one,
why
did
the
community
suggest
rust
as
a
main
language
in
the
linux
kernel?
They
emphasize
especially
things
like
memory,
safety
and
absence
of
data
races.
They
think
that
rust
offers
a
very
strict
type
system
which
offers
rich
abstractions
and
lead
to
a
reduction
of
logic
errors.
A
A
Okay?
It
will
also
it
will
only
pay
off
if
you
invest
in
a
technology
if
it's
not
just
great
and
has
a
great
a
great
community,
but
it
also
has
to
have
sponsoring
to
answer
the
question:
will
it
be
there
in
a
few
years?
Will
it
be
worth
my
time
to
invest
some
time
here,
and
this
is
definitely
the
case
with
rust?
If
you
take
a
look
at
some
of
the
big
ones
in
current
it,
industry,
then
take
a
look
at
what
microsoft
says.
A
Microsoft
says
that
rust
can
solve
some
of
the
most
vexing
issues
that
plague
c-plus
plus
projects
or,
if
you
take
a
look
at
google's
security
block,
they
are
praising
rust
for
its
safety
guarantees.
At
the
same
time,
while
offering
equivalent
performance
to
cnc
plus
plus,
take
a
look
at
what
facebook
says.
For
instance,
they
say
that
rust
offers
the
performance
of
c
plus,
while
having
a
heavy
focus
again
on
code
safety.
A
Hundreds
of
developers
at
facebook
are
currently
writing
millions
of
lines
of
rust,
so
rust
is
definitely
in
the
middle
of
the
of
the
core
cloud
business
in
the
I.t
world.
Rust
has
organized
itself
currently
in
the
rust
foundation.
The
rest
foundation
is
an
independent
non-profit
organization
which
leads
and
steals
the
rust
programming
language
ecosystem.
A
A
A
Now,
let's
go
into
the
next
topic
and
take
a
look
at
the
first
technical
things.
I
mentioned
it
quite
a
few
times
that
rust
offers
best
in
class
safety
and
stability
better
than
even
c
c,
plus
plus
or
some
managed
languages.
Let's
take
a
look
at
that
and
let's
take
a
look:
what
rust
can
offer
here
and
how
rust
will
do
it
in
this
chapter
and
in
the
upcoming
chapters,
you
will
see
a
lot
of
code
samples.
A
Please
don't
focus
too
much
on
the
details.
I
only
have
45
minutes
so
try
to
get
the
concept,
try
to
get
the
big
picture
out
of
the
out
of
the
code.
Examples
if
you
want
to
know
really
more
about
it.
I
share
my
slide
deck
with
you
and
after
the
talk,
if
you
are
as
excited
about
rust
as
I
am,
you
can
dive
into
the
code
snippet
and
take
a
look
at
the
details
before
we
take
a
look
at
rust's
solution
to
the
safety
problem.
Let's
take
a
look
at
the
basic
problem.
A
Consider
this
code
sample
it
is
in
c
you
have
a
main
method
which
calls
the
get
and
process
data
method
which
in
turn
calls
the
getdata
method
and
there
we
have
a
big
problem
because
inside
the
getdata
method
a
memory
allocation
takes
place
and
if
you
take
a
look,
the
memory
is
returned
from
getdata
and
is
never
freed
inside
of
get
and
process
data.
So
we
have
the
problem
that
we
have
a
memory
leak.
It's
not
clear
who
is
responsible
for
freeing
the
allocated
memory.
A
A
But
for
the
sake
of
this
demo,
I
guarantee
you
that
code
like
that
still
exists
out
there
and
if
you
take
a
look
at
public
studies,
for
instance
from
microsoft,
they
show
that
for
years
and
years
and
years
a
lot
of
the
vulnerabilities
have
their
roots
in
memory.
Problems
exactly
like
that,
so
this
is
definitely
a
problem.
A
A
That
is
also
a
very
well-known
vulnerability
and
it
commonly
presents
a
problem
to
all
the
source
code
bases
if
you
think
that
those
problems
like
use
after
free
and
things
like
that
are
just
present
in
unmanaged
languages
like
c
and
c
plus
plus,
then
you
are
not
completely
right.
This
example
is
a
managed
language
with
the
garbage
collector
it's
written
in
c
sharp
and
in
c
sharp
you
have
the
concept
of
disposing
objects
that
you
no
longer
need.
A
That
means
you
explicitly
free
memory
or
free
dependencies
to
memory,
and
you
can
write
very
similar
codes
to
what
we
have
seen
in
c
before
so
I
can
dispose
an
object
in
this
case,
for
instance,
a
connection
to
a
database
and
use
it
afterwards.
This
will
not
lead
to
a
security
vulnerability,
but
it
will
lead
to
a
to
a
runtime
error
to
your
software
crashing
to
your
customers
complaining
and
that's
also
a
problem.
Definitely.
A
Now,
let's
take
a
look
at
the
last
example
before
we
take
a
look
at
the
rules
of
rust
and
how
rust
solves
this
problem.
Take
a
look
at
this
source
code.
In
this
case
we
have
the
following
situation:
we
have
a
main
method.
This
main
method
calls
into
a
print
value
function
and
this
print
value
function
receives
some
memory
and
it
thinks
that
it
is
the
job
of
the
print
value
method
to
free
this
memory.
A
Unfortunately,
the
author
of
the
main
method
has
the
same
idea
and
she
is
also
cleaning
up
the
memory
inside
the
main
method.
So
this
is
a
classical
double
free
problem
which
can
lead
to
memory,
corruption,
crashing
software
and
many
other
things.
A
well-known
problem
well
documented
in
in
in
projects
like
oh
wasp,
for
instance.
A
Again,
the
double
free
problem
is
not
just
about
unmanaged
languages.
Here
you
see
an
example
that
you
might
come
across
when
you
write
code
in
c
sharp
in
a
managed
language
with
the
garbage
collector
for
performance
reason,
a
language
like
c
sharp
offers
so-called
memory
pools
or
array
pools
where
you
can
get
memory
for
large
arrays
out
of
it,
and
you
can
return
those
memory
areas
later
on.
If
you
don't
no
longer
need
it.
A
A
So
such
memory
problems
are
really
really
a
problem
and
endless
studies
I
mentioned
it
before
have
shown
that
they
lead
to
code
vulnerabilities
and
to
software.
That
is
not
as
stable
as
it
should
be,
so
how
does
rust
solve
exactly
that?
Rust
solves
it
by
specifying
a
few
simple
but
powerful
rules
for
memory
management.
A
First,
in
rust,
each
piece
of
memory
each
variable
like
at
least
a
vector
or
a
string
or
whatever
has
an
owner.
It
is
assigned
to
a
certain
owner.
There
can
only
be
one
owner
at
a
time
and
if
I
allocate
some
memory
and
if
I
hand
this
memory
over
to
somebody
else,
I
can
give
away
the
ownership.
There
is
always
exactly
one
owner
of
memory
at
one
particular
point
in
time.
You
can
call
it
the
highlander
effect
if
you're
old
enough
old
enough.
A
A
That
is
important
and
now
comes
the
most
important
statement
of
the
entire
slide.
These
ownerships
are
not
just
ensured
during
runtime,
but
they
are
enforced
by
the
compiler.
That
means
in
rust.
If
you
write
some
code
and
you
and
you
write
code,
that
does
not
follow
the
rules
that
I
stated
here,
the
compiler
will
complain.
You
will
not
get
a
runtime
error
and
that
is
pretty
powerful
for
beginners.
It's
sometimes
hard
to
work
with
these
rules
because
you
get
so
many
compiler
errors.
A
A
A
This
vector
is
stored
in
a
variable
called
numbers
in
line
6.
We
assign
numbers
to
other
numbers
and
in
line
10,
we
print
the
content
of
the
vector
on
the
screen.
The
colon
question
mark
inside
the
curly
braces
mean
that
I
want
to
have
debug
output.
Now,
let's
take
a
look
what's
happening
with
the
ownership.
First,
the
variable
numbers
owns
the
vector,
so
the
ownership
is
clear
and
now
comes
the
important
one.
The
ownership
changes
in
line
six
in
line
six,
the
ownership
goes
from
numbers
to
other
numbers.
A
So
if
you
would
try
to
access
numbers
in
line
11,
as
shown
here,
this
will
lead
to
an
error,
but
not
just
to
a
runtime
error,
but
this
will
lead
to
a
compile-time
error.
It's
simply
not
allowed
ownership
has
changed.
Numbers
does
no
longer
own
the
memory.
Therefore,
you
cannot
access
the
vector
through
numbers.
A
Of
course,
if
you
take
a
look
at
this
little
bit
extended
and
changed
example
of
what
we
saw
before
it
is
possible
to
clone
memory.
In
this
case,
we
clone
the
other
numbers
into
clone
numbers.
Then
we
have
two
different
owners,
but
we
also
have
two
different
areas
in
memory,
so
it
isn't
the
problem
that
we
now
have
two
owners
and
therefore
it's
perfectly
fine,
take
a
look
at
line
16
that
we
access
cloned
numbers
and
other
numbers.
So
cloning
is
perfectly
okay.
A
Let's
take
a
look
at
another
sample
and
this
sample
is
about
ownership
and
functions.
Let's
again
start
at
the
very
top
take
a
look
at
line.
Two
again
we
allocate
a
vector
and
store
it
in
a
variable
called
numbers,
but
then
recognize
what
we
do
in
line
three
in
line
three,
we
give
the
vector
owned
by
numbers
to
a
method
which
is
called
consume,
so
the
ownership
changes,
the
ownership
goes
into
the
method
consume
and
now
numbers
numbers
belong
to
the
function
consume.
A
When
the
local
variable
numbers
goes
out
of
scope,
the
vector
is
freed.
It
is
not
possible
to
access
numbers
in
the
main
method
after
the
call
to
consume,
so
we
have
a
transfer
of
the
ownership
between
the
main
method
and
the
consume
method.
And
again
we
have
the
rule
valid.
We
only
can
have
one
owner
at
one
exactly
point
in
time
now,
let's
take
it,
take
a
look
at
the
other
side.
A
Here
we
have
a
function
which
is
called
produce
and,
as
you
can
see,
in
line
16,
this
function
produces
a
vector,
so
it
allocates
a
vector
in
line
17
pushes
some
numbers
into
this
vector
and
returns.
The
number
for
those
of
you
who
are
not
that
familiar
with
rust
line
19
does
not
contain
a
return
statement,
but
please
note
that
the
line
19
does
not
have
a
semicolon
at
the
end
of
the
line.
That
means
it
is
the
returned
value
from
the
function.
A
This
is
the
syntax
of
rust,
so
by
returning
numbers
and
the
vector
the
ownership
moves
to
the
main
method.
Now
the
main
method
has
the
ownership
and
stores
the
vector
in
produced
numbers,
and
then
we
can
print
produced
numbers
and
when
produced
numbers
goes
out
to
scope,
the
memory
is
freed.
We
have
one
owner
at
one
particular
point
in
time.
A
What
about
borrowing,
borrowing
means
that
a
method
allocates
some
memory
and
it
would
like
to
hand
over
control
over
this
memory
for
a
limited
amount
of
time
to
another
function,
and
that
is
the
case
in
our
consume
function,
because
our
consume
function
is
only
reading
memory
from
the
rector
it
doesn't
need
ownership.
It
just
needs
to
be
able
to
read
from
the
vector,
and
the
good
news
is
that
you
can
borrow
read.
Only
borrow
a
single
piece
of
memory
to
multiple
functions.
Take
a
look
at
this
function
here.
A
A
Now.
If
we
take
a
look
at
the
second
function,
add
and
consume.
It
is
important
to
see
that
this
time
the
function,
it
also
gets
a
reference
to
the
vector,
but
it
gets
a
mutable
reference
to
the
vector
and
therefore
the
borrow
mutable.
There
can
also
be
just
one
mutable
borrow,
but
still
it
is
a
borrow.
So
the
main
method
still
has
the
ownership
of
the
numbers,
but
for
a
limited
amount
of
time,
add
and
consume
can
read
and
write
to
the
back
door.
A
As
you
can
see
in
line
20,
where
I
push
the
value
42
into
the
vector,
as
I
said,
the
main
method
is
still
the
owner,
so
we
can
at
the
end
print
the
resulting
content
of
the
vector
and
rust
will
automatically
free
the
vector.
It
is
absolutely
clear
that
it
can
free
the
vector
at
the
end
of
the
main
method,
because
the
main
method
and
the
variable
numbers
owns
the
vector.
A
Let's
take
a
look
at
another
example,
which
is
pretty
common
when
you
write
code,
let
me
quickly
lead
you
through
this
example.
This
time
we
are
taking
a
look
at
an
async
function.
Please
take
a
look
at
line
9,
which
is
an
async
main
method
and
please
take
a
look
at
line
20.
The
sum
method,
as
you
can
see,
the
async
main
method
in
line
10
allocates
again
a
vector
and
then
calls
the
sum
method,
but
the
sum
method
has
some
weight
statements
in
it.
A
A
In
this
case,
I'm
just
simulating
some
work
by
waiting
for
two
seconds
and
at
the
end
of
the
day,
I'm
returning
the
sum
over
the
numbers,
but
the
method
sum
will
be
active
for
at
least
two
seconds
and
if
you
take
a
look
in
line
12,
while
the
sum
method
runs,
we
add
something
to
the
numbers,
and
that
is
not
possible
rust.
It
would
break
the
iterator
and
it
would
break
our
ownership
rules.
A
We
cannot
borrow
the
vector
and,
on
the
other
hand,
borrow
the
mutable
vector
to
the
add
method
at
the
same
point
in
time,
it's
not
possible.
The
big
thing
here
is
rust
will
give
you
a
compile
time
error
if
you
do
something
like
that,
the
same
code
in
c
sharp
in
a
managed
language
with
the
garbage
collector
would
look
like
that.
I
will
not
go
into
the
details
because,
even
if
you
have
not
written
c
sharp
before,
you
will
probably
be
able
to
read
and
understand
the
the
code
from
the
context.
A
Let's
take
a
look
at
at
the
last
more
complicated
example.
This
example
works
with
so-called
channels
take
a
look
at
line,
six,
I'm
creating
a
channel
of
integers
here,
and
I
would
like
to
solve
a
producer
consumer
problem,
so
I'm
spawning
in
line
eight
a
producer
thread,
and
this
thread
pumps
some
values
in
this
case
just
some
integer
values
into
this
channel
and
between
each
channel
between
each
send
operation.
We
wait
for
500
milliseconds,
that's
the
producer
and
please
take
a
look
at
the
move
keyword
here.
A
The
move
keyword
means
that
the
captured
variable,
in
this
case,
the
sender
variable
which
we
get
from
the
channel
in
line
six,
is
move.
The
ownership
is
moved
into
the
lambda
function
of
the
thread,
so
there
can
only
be
just
one
sender
inside
the
producer
thread,
but
if
you
take
a
look
at
the
bottom,
this
is
the
receiver
part
of
the
channel.
You
see
the
receiver
part
was
generated
by
producing
the
channel
in
line
6..
Now
we
can
safely
call
receiver.receive
and
match
over
the
result
and
print
the
result.
A
Once
we
got
something,
if
you
are
new
to
rust-
and
you
wonder,
hey
what's
this
match
all
about,
and
what's
this
okay
and
error,
please
be
patient
for
another
few
minutes,
you
will
learn
more
about
it.
So,
as
you
can
see,
the
borrowing
rules
also
apply
to
more
complicated
multi-threaded
programming
scenarios
where
you
have
sender
and
receiver
running
in
different
threads.
A
So
what
can
we?
What
can
we
summarize
rust
is
really
stable
and
safe.
It
has
clear
ownership
rules
and
the
important
thing
that
you
should
remember
from
this
talk
is
those
ownership
rules
are
enforced
by
the
compiler.
Of
course.
Sometimes
things
are
not
that
simple.
If
you
explicitly
want
to
have
shared
memory
with
multiple
pieces
of
code
accessing
reading
and
writing
a
certain
element
of
memory,
of
course,
this
is
possible
in
rust,
of
course,
but
this
should
be
the
exception
and
not
the
rule
for
the
typical
everyday
programming
rust.
A
There
is
a
second
aspect
here
in
this
enforcing
of
the
rules
by
the
compiler
and
that's
about
performance,
because
the
compiler
enforces
so
many
strict
rules.
It
can
optimize
the
codes
to
a
very
large
extent
without
being
afraid
to
break
something.
So
the
performance
is
simply
awesome,
a
managed
language
that
has
to
do
all
these
checks
at
runtime
obviously
needs
cpu
cycles
for
doing
the
checks.
Here.
The
checks
are
at
compile
time
and
not
at
runtime
good.
A
The
next
topic
is
about
deepness,
a
relationship
that
I
would
like
to
have
with
a
programming
language
should
be
deep.
I
want
to
have
a
deep
type
type
system.
I
would
like
to
have
the
the
language
to
support
myself
to
make
the
best
out
of
my
ideas
to
offer
me
great
abstractions
and
things
like
that.
So
for
the
next
few
minutes,
I
would
like
to
walk
you
through
some
examples:
some
small
examples
about
the
type
system
in
rust.
So
you
understand
better
how
you
create
abstractions,
doing
structured
programming
and
things
like
that
with
rust.
A
First
rust
has
no
classes.
So
if
you
come
from
programming
languages
like
java,
c-sharp,
typescript
and
so
on,
you
obviously
think
that
rust
will
have
something
like
classes,
inheritance,
polymorphism
and
things
like
that.
I'm
afraid
not
rust
has
structs.
Structs
is
the
basic,
the
basic
building
block
of
creating
data
structures
in
rust,
and
here
you
have
three
examples
for
structures,
structures
with
basic
data
types
like
float,
32
and
also
composed
structures
like
rectangle
and
circle.
A
If
you
want
to
work
with
these
structs,
it's
obviously
clear
that
you
can
create
instances
of
these
structs,
as
you
can
see
in
line
three,
but
it's
also
possible
to
create
duplicates
and
copy
parts
of
another
struct
into
a
new
instance
of
the
struct,
with
a
dot
dot
syntax.
As
you
can
see
here
in
line
six,
isn't
that
beautiful
syntax?
I
love
this
syntax,
I'm
also
doing
a
lot
of
work
in
the
c-sharp
area,
and
there
you
have
this
with
clause.
A
It
only
came
recently
to
c-sharp,
but
rest
has
it
built
in
for
quite
quite
a
while
another
example
that
is
worth
mentioning
is
this
one:
by
default,
variables
in
rust
are
immutable,
so
line
three
and
line
six
create
immutable
points.
If
you
want
to
be
able
to
mutate
a
variable
or
its
content,
you
have
to
just
declare
it
as
being
mutable
like
you
can
see
in
line
10
then,
and
only
then
I
can
change
the
content
of
the
rectangle
that
I
create
in
line
10.
A
all
the
examples
above
created
instances
of
the
structs
on
the
stack,
but
obviously
you
can
create
instances
on
the
heap
too,
and
for
that
rust
offers
a
lot
of
different
data
types
like,
for
instance,
box.
In
this
case,
box
new
would
would
create
an
instance
of
in
this
case
the
circle
create
the
circle
on
the
heap
and
return
a
reference
to
the
heap
into
your
variable
c,
which
again
is
marked
as
being
mutable.
Therefore,
in
917
we
can
change
the
radius
of
the
circle,
so
that
is
structs.
A
Let's
take
a
look
at
functions.
You've
always
already
seen
that
in
rust,
you
can
simply
create
standalone
functions,
functions
that
have
no
relation
to
any
kind
of
data
structure,
but
you
can
also
add
implementations
to
structs
by
adding
functions
to
a
struct.
Please
take
a
look
at
line.
One
you
see.
We
have
the
implementation
of
the
rectangle
struct
that
you
saw
before
and
line.
15
shows
you
that
there
is,
or
there
can
be,
a
function
area
which
gets
a
borrow.
A
A
borrowed
reference
to
self
meaning
the
rectangle,
and
therefore
you
can
read
from
self
by
calculating
the
area
by
multiplying,
with
with
height
enlarge,
is
another
example
of
a
bound
function,
a
function,
bounds
to
the
structure
rectangle
this
case
it
gets
a
mutable
borrow
of
itself
and
therefore
we
can
change
the
content
of
the
rectangle
in
place.
So
we
can
in
line
11
and
12
change
the
x
and
y
coordinates
by
multiplying
doing
some
multiplication,
some
basic
math.
I
think
you
get
the
point
here.
A
The
second
example
here
is
circle
and
circle
contains,
as
you
can
see
it
here,
a
kind
of
constructor
function.
Unit
circle
gives
you
a
new
instance
of
circle.
By
creating
it.
That
is
the
analogy
to
a
constructor
in
other
languages.
There
isn't
a
notion
like
a
constructor.
Instructs,
you
create
such
constructor
functions
and
you
can
use
them
to
instantiate,
in
this
case
a
circle
so
an
instance
of
the
struct
on
the
right
hand,
side
in
line
one
you
see
how
unit
circle
is
used.
A
Once
you
discovered
structs,
the
next
thing
that
you
have
to
understand
with
rust
is
traits.
If
you
know
interfaces
from
other
languages,
you
have
a
rough
idea
about
what
traits
can
be
traits
like
in
line.
1
are
kind
of
collections
of
functions
that
have
to
be
implemented
by
a
struct
in
order
to
implement
the
trait.
A
In
this
example,
I
created
the
area
trait,
which
requires
the
existence
of
an
area
function
which
borrows
an
instance
of
the
object
and
returns
the
calculated
area
as
a
float
32-bit,
and
then
in
line
5.
You
see
how
I
implement
the
area
trait
for
the
rectangle
by
saying
implement
area
for
rect.
Of
course,
I
can
also
implement
area
for
circle,
as
you
can
see
it
from
in
line
11
and
further.
A
Now,
let's
take
a
look
at
how
we
can
use
traits
on
the
right
hand,
side
you
see
that
I
create
a
shape
with
area
and
assign
it
to
a
reference
of
a
rectangle,
and
the
important
thing
is
the
dynamic
reference
in
line
five.
You
see
it
here
in
the
yellow
rectangle.
That
means
that
the
resolution
of
the
functions
is
done
dynamically
based
on
the
underlying
type,
so
area
from
rectangle
is
called
if
shaped
with
area
as
a
rectangle
circle.
That
area
is
called
if
it
is
a
circle.
A
So
this
is
what
basic
traits
are
all
about,
but
traits
in
rust
are
used
all
over
the
place,
and
here
you
see
two
important
system
traits
that
you
have
that
are
great
to
describe
the
con,
the
the
concept
of
traits
and
how
it
is
used
in
the
base
library
in
the
standard
library
of
rust.
Take
a
look
at
the
display
trait.
The
display
trait
was
not
defined
by
me,
but
it
is
defined
by
the
rest
standard
library.
A
I
can
implement
it
for
a
data
structure
like
point
to
make
a
log
story
short
in
display.
I
have
to
provide
a
text
representation
for
my
data
structure.
Please
take
a
look
in
line
13
here,
I'm
just
building
a
text
representation
with
some
json-like
data
structures
and
implement
the
display.
Trait
with
that,
and
therefore
I
can
take
a
look
at
the
bottom.
In
line
two
use,
the
print
line
macro.
A
A
Now
you
have
seen
multiple
times
these
exclamation
marks
at
the
end
of
some
words
like
vec,
exclamation,
mark
or
print
line,
exclamation
mark
macros
are
behind
that.
Macros
can
exist
as
as
you
can
see
here,
on
top
of
the
struct
point
here,
and
this
macro
is
an
example
to
auto
generate
an
implementation
of
a
trait
for
the
structure.
Don't
get
me
wrong,
you
cannot
just
use
macros
for
implementing
traits
you
can
you
can
use
macros
to
generate
code?
A
That
does
anything
that
comes
to
your
mind.
In
this
case,
I'm
using
the
system
drive
macro
telling
the
system
to
auto
generate
the
so-called
debug
trade,
and
the
debug
trade
will
make
sure
that
I
can
use
debug
output
for
my
structure
and
in
this
case
it
will
just
take
this.
The
elements
of
my
point,
which
are
two
basic
data
types
like
floats,
so
just
data
types
which
also
implement
the
debug
trade
to
generate
another
higher
abstraction
level,
debug
trade.
For
me
automatically.
I
do
not
need
to
write
code.
A
This
is
done
during
compile
time,
not
during
runtime
the
code
generation
here.
So
this
is
an
alternative
to
what
in
many
managed
languages
is
done
through
reflection,
for
instance,
or
this
example
here
this
you've
seen
this
before
this
wac
exclamation
mark
is
a
macro
that
makes
it
easier
to
create
a
vector
of
things
and
therefore,
if
you
do
that,
you
can
use
the
print
line
macro,
which
will
care
for
displaying
the
formatted
output
as
specified
here
in
line
five
on
standard
out.
A
A
The
next
thing
that
I
would
like
to
speak
about
are
enums.
I
guess
you
know
what
enums
are
from
languages
like
java,
like
c
sharp
or
typescript,
but
enums
in
rust
are
more
powerful
because
enums,
as
you
can
see,
in
line
8
and
nine
can
have
values
so
think
about
poker
moves.
I
don't
know
if
you
play
poker
or
if
you
ever
played
poker,
but
in
poker
it
is
possible
to
call
a
hand.
A
That
means
you
have
to
place
the
same
amount
of
money
into
the
pot
that
is
already
in
the
pot
or
you
can
raise
so
you
have
to
you,
have
to
put
even
more
money
into
the
pot
and,
as
you
can
see
here,
the
enum
poker
move
contains
a
fold
means
I'm
stopping
I'm
no
longer
playing
calling
and
raising
and
calling
and
raising
get
parameters
to
the
enum.
That's
a
special
case
for
enums
in
rust
and
enums
are
also
exactly
as
powerful
as
stocks
are.
They
can
implement
traits,
and
things
like
that.
A
Enums
are
additionally
deeply
integrated
into
the
rest
of
the
language.
Take
a
look
at
the
match
statement
here.
The
match
statement
allows
you
to
specify
all
possible
values
of
the
enum
and
rust
will
make
sure
that
you
do
not
forget
a
single,
a
single
value
that
is
possible
in
the
enum.
So
if
you
don't
have
the
line
five
default
value
here,
it
would
raise
a
run
to
a
compile
time
exception,
because
you
have
to
specify
a
defined
behavior
for
every
for
every
value
of
the
enum.
You
cannot
forget
anything
again.
A
That's
a
question
of
safetyness
enums
are
widely
used
inside
the
standard
library,
for
instance.
I
would
like
to
point
out
the
option
enum.
It's
part
of
the
rust
standard
library,
and
it
is
the
it
is
the
the
replacement
of
null
by
default.
If
you
are
not
using
some
unsafe
pointer
magic
by
default,
a
variable
in
rust
cannot
be
null.
It
is
not
possible,
but
at
some
point
you
maybe
have
to
represent
that
a
variable
has
a
value
or
doesn't
have
a
value,
and
here
a
good
example
is
the
option.
A
Enum
option,
as
you
can
see,
in
line
11
and
12
can
have
two
different
values:
either:
none
if
it
doesn't
have
a
value
or
sum
with
a
value
parameter
if
it
has
a
value,
and
here
in
this
example,
I'm
using
an
iterator
to
get
the
fifth
element.
It's
zero
based
from
an
iterator
if
it
finds
a
value.
I
go
into
the
sum
part
of
my
program
found
a
move
if
it
doesn't
find
a
move
inside
the
vector
it
enters
the
non-part
of
the
match
clause.
A
So,
as
you
can
see
here,
this
is
obviously
often
used
inside
the
standard
library.
Also,
the
result.
The
optional
result
of
a
function
which
can
either
be
a
result
or
an
error,
is
represented
by
an
enum.
The
result
enum
is
frequently
used.
The
result
enum
can
either
be
okay
with
the
resulting
data.
In
this
case,
it
read
some
string,
some
data
from
file
or
the
error
thing
here,
which
will
which
will
represent
the
error
that
happens
when
accessing
the
file
main.rs
in
this
example.
A
So
you
see,
enums
are
also
a
building
block
of
the
core
type
system
of
rust.
So,
to
make
a
long
story
short
rust
has
deepness,
it
has
powerful
feature-rich
type
system.
It
has
a
lot
of
built-in
types
like
basic
data
types
standalone
functions,
things
like
that,
but
it
has
structs
enums
traits
and
macros
as
the
foundation
for
building
powerful
class
libraries
applications
standard
libraries,
whatever
you
want
to
build,
and
then
there
are
so
many
small
traits
as
a
developer.
I
sometimes
love
this
small
little
simple
things
which
really
make
my
life
easier.
A
I
will
go
very
quickly
to
some
of
the
things,
so
you
see
that
the
reason
why
I
really
love
to
use
rust.
So,
let's
take
a
look
at
the
first
street.
The
first
street,
as
I
mentioned
before,
is
mutables
shadowing
and
sorry.
Mutables,
shadowing
and
freezing
take
a
look
at
line.
One
we
get
a
location
which
is
a
reference
to
a
string.
It
can
either
be
a
string
or
a
string
slice
or
something
like
this,
but
notice
that
inside
the
function
I
also
define
a
variable
called
location
in
many
other
languages.
A
A
Think
of
you
have
a
mutable
value
and
for
some
area
in
your
code,
you
would
like
to
freeze
this
value,
so
you
can
open
a
code
block
like
shown
here,
assign
the
mutable
value
to
an
immutable
value
and
suddenly,
inside
the
code
block
the
value
is
frozen.
You
cannot
accidentally
assign
a
value
to
it.
When
you
leave
the
code
block,
take
a
look
at
line
14
you
can
assign
something
to
the
value
again
beautiful,
isn't
it
mutability,
shadowing
and
freezing
or
error
propagation?
Take
a
look
at
this
small
question
mark
here
in
this
case.
A
Result
from
me
from
the
method
read
data
that
I'm
currently
implementing
it's
called
error:
propagation,
beautiful,
isn't
it
nice
to
write
or
another
thing
in
this
case,
I
want
you
to
focus
not
on
the
code,
but
I
want
you
to
focus
on
the
comments.
Can
you
see
the
example
section
in
the
comments
here
believe
it
or
not?
That's
executable
rust
code
in
rust.
You
can
add
examples
to
the
docs
and
you
can
test
the
code.
Take
a
look
at
the
screenshot
in
the
right,
lower
corner.
A
You
can
see
that
I
call
cargo,
which
is
the
build
tool
of
rust
cargo
test
dock
and
it
will
execute
the
code
inside
of
the
documentation
and
also
make
sure
that
it
doesn't
panic.
So
you
can
add
some
kind
of
assertions
just
like
unit
tests.
Speaking
of
unit
tests,
obviously
rust
has
a
concept
of
unit
tests.
Here
you
see
just
a
simple
example,
but
you
have
to
take
a
look
into
the
documentation
to
read
more
about
it.
A
Another
quick
one
and
then
we
have
to
come
to
an
end
is
type
interference.
Do
you
see
line
two?
We
create
the
vector
off.
Well,
we
have
no
idea.
We
just
create
a
vector
and
ask
rust
to
figure
out
the
type
of
the
vector
later
on.
It
takes
a
look
at
line
4
and
says:
oh
reiner
is
pushing
an
integer
32
bit
into
the
vector,
so
I
understand
that
this
vector
now
has
the
type
integer
32.
So
I
can
not
push
a
string
value
into
this
vector.
A
A
If
you
are
curious,
if
you
think
that
maybe
this
is
a
loving
and
caring
relationship
for
you
for
us
and
for
us
for
you,
then
you
might
take
a
look
at
these
options.
You
have
gotten.
I
think
the
link
to
my
slides
already
in
the
chat
rust
has
a
great
rust
book
which
is
available
for
free
online.
Just
click
on
the
link,
and
you
have
the
book
just
install
rust
and
start
coding.
The
best
way
of
learning
a
programming
language
is
by
practicing
it.
A
There
is
also
a
great
website
which
is
called
exorcism,
with
lots
and
lots
of
small
examples
which
allow
you
to
make
a
gradual,
step-by-step
entry
into
this
new
language.
You
can
visit
a
meet
up
and
I
couldn't
resist
to
add
a
link
to
our
own
rust,
lintz
meetup,
where
I'm
one
of
the
founder
and
hosts
of
so.