►
From YouTube: Diving headfirst into Rustland: A primer to avoid getting lost - unknowntrojan - Rust Linz August 23
Description
This talk is aimed at experienced C++ devs looking to try Rust, not serving as an introduction or tutorial but simply an orientation quickly going over language features that may be alien to a C++ developers.
Material: https://github.com/unknowntrojan/talks
A
A
Thanks
for
attending
and
this
talk
is
called
diving
head
first
into
rustland
and
I,
designed
it
as
a
talk
to
help
CPUs
plus
developers
that
maybe
want
to
try
rust,
not
get
lost
while
trying
to
start
learning
rust
so
about
me.
I'm
currently
employed
at
the
Avalanche
game,
Bihar
in
I've,
been
using
C
plus
plus
for
a
very
long
time.
Basically,
since
I
can
remember,
I
have
a
background
in
reverse
engineering
and
game
hacking,
so
usually
low
level
stuff
and
upon
a
friend's
recommendation.
A
I
tried
rust
around
two
years
ago
and
I've
been
completely
loving
it
so
I'd
like
to
give
back
with
this
talk.
What
I
would
have
loved
to
have
watched
myself
back
then
yeah
that
just
says
that
okay,
we
will
quickly,
but
not
too,
in
depth,
go
over
the
style
of
rust
code,
expressions
and
parts
of
functional
programming
we'll
be
going
over.
A
First
of
all,
I
want
to
quickly
remind
everyone
that
the
documentation
for
rust
is
absolutely
amazing
and
that's.
This
is
not
a
replacement
for
any
of
these
by
far
and
if
you've
read
docs
before
and
don't
like
that
and
haven't
read
these
before
I
recommend
trying
them
because
they
are
really
really
good
so
about
rust
style
compared
to
a
lot
of
other
languages.
Rust
enforces
a
pretty
strict
code
style
guideline,
as
opposed
to
other
languages,
where
it's
more
or
less
a
fair
everybody
can
have
their
own
style,
so
reading
runs
code.
A
Then
expressions
so
rust
makes
heavy
use
of
Expressions
a
lot
of
constructs
like
blocks
if
expressions
and
match
Expressions
sorry,
foreign
I'm
blocking
a
lot
of
constructs
that
are
statements
in
other
languages
are
expressions
in
Rust,
for
example,
blocks.
If
expressions
are
match
Expressions.
This
means,
for
example,
if
you
want
to
quickly
compute
a
value
and
just
place
it
as
an
argument
somewhere,
you
don't
have
to
pre-compute
it
put
it
in
a
variable
and
then
assign
it.
You
can
then
pass
it.
A
You
can
just
put
that
block
right
there
and
let
it
evaluate
a
c,
often
users
or
basically
only
uses
switch
cases
for
jump
tables
and
having
a
conditional
Branch
with
a
huge
amount
of
potential
branches
and
rust
with
its
matching
match.
Expression
allows
a
much
cleaner,
syntax
than
what
C
users
might
be
used
to.
A
A
Here's
an
example
of
a
block
of
code
as
an
expression
just
very
useful
in
general,
then
a
functional
programming,
so
raspberries
a
lot
of
Concepts
from
languages
like
oh
camo.
It
makes
heavy
use
of
iterators,
making
it
easy
and
efficient
when
operating
on
collections
of
data.
A
A
Then
the
memory
management,
one
of
the
biggest
talking
points
when
I
heard
about
rust
at
first,
was
that
memory
bugs
were
harder
to
make
I
guess
and
at
the
time
I
thought
you
know.
C
plus
plus
you
can
make
those
errors,
but
just
don't
make
those
errors.
It's
not
worth
it
to
have
the
compiler
hold
your
hand,
and
you
know
like
stop
you
from
doing
stuff.
A
You
want
to
do,
but
then,
when
I
actually
did
learn
rust
at
first,
it
did
feel
like
somebody
was
holding
me
back,
but
after
a
while
the
your
code
just
adjusts
and
you
don't
feel
the
borrow
Checker
at
all
and
your
code
is
safe,
so
I
believe
if
this
is
like
an
argument
for
you
to
not
try
rust,
to
reconsider
the
rust
compiler
enforces
memory
safety
at
compile
time.
This
way,
using
a
few
rules,
every
variable
has
an
owner
and
that
owner
has
a
scope.
A
When
the
variable
goes
out
of
scope,
the
variable
is
dropped
and
a
certain
trait
allows
the
variable
to
clean
up
after
itself,
if
necessary,
the
default
implementation
simply
moves
the
value
into
a
scope
and
then
leaves
the
scope.
Variables
are
also
moved
by
default,
and
references
to
a
variable
can
only
be
giving
out
given
out
in
line
with
us
borrowing,
rules
oops.
A
That
is
way
farther
back
as
I
I'm,
pretty
sure.
A
lot
of
you
know
there
can
be
only
one
mutable
reference
to
a
variable
at
a
time
and
no
immutable
reference
references,
while
the
mutable
reference
is
active.
This
prevents
data,
races
and
Views
after
prepared
exactly
and
no
immutable
references.
While
the
multiple
reference
is
active.
If
the
variable
is
not
mutably
borrowed,
it
can
be
immune
to
be
borrowed
as
often
as
desired
since,
when
nothing's
modifying
it,
you
can't
have
a
data
race.
A
Repository
called
crates.io
that
everybody
can
publish
packages
to
and
immediately
pull
down
and
compile
if
they
want
to
also
adding
a
dependency
from
a
git
repository
or
a
path
is
very
easy,
so
you
can
have
multiple
projects
in
a
git
repository
and
simply
have
them
as
dependencies
on
each
other.
It
will
also.
It
is
also
consistently
used
on
almost
every
single
bus
project,
so
you
can
have
a
cargo
project
and
every
other
project,
basically
that
we
will
ever
encounter,
will
also
have
cargo.
A
A
rust
project
is
called
the
crate.
It
can
be
either
a
library
or
a
binary
crate,
and
they
can
expose
feature
flags
that
the
end
user
can
select
and
basically
shape
the
library's
Behavior
to
their
requirements,
creates
our
versioned
using
sember
and
when
adding
a
crate
as
a
dependency,
you
specify
a
constraint
to
tell
cargo
which
versions
are
fine
to
use.
It
will
pull
the
newest
that
matches
the
criteria
and
then
put
it
in
a
log
file,
and
unless
you
manually
tell
it
to
update
or
delete
the
log
file,
it
will
keep
using
that
version.
A
A
You
would
use
I
didn't
not
say
that
before
I
did
in
Rust,
the
switch
syntax
is
improved
upon
with
a
match
expression
that
allows
writing
more
readable
code,
and
it
looks
something
like
this,
which
I
think
is
better
than
case
Zero
print
line
and
then
a
break
enums.
My
favorite
topic
here,
rust
enum
variants
can
not
only
be
numeric
as
in
some
other
languages,
but
contain
any
arbitrary
type
the
user
wants.
For
example,
rust
has
two
very
common
enorms
that
are
basically
used
everywhere
in
Rust
code,
option,
T
and
results.
A
T
error
option
can
be
one
of
two
variants:
none
and
some
so
there's
no
need
for
null
Sentinels.
If
a
function
can
conditionally
return.
A
value,
for
example,
option
is
used
to
let
the
user
easily
match
on
it
and
decide
what
to
do.
Result
can
be
one
of
two
variants.
As
well
OK
and
er
this
time,
though,
the
OK
variant
which
we,
which
would
have
been
equivalent
to
none
before
and
no
never
mind
it,
does
contain
a
value.
T
and
error
contains
a
value
e.
A
It
is
the
enum
used
for
error
handling
and
if
a
function
can
fail,
it
will
simply
return
a
result,
and
this
result
T
will
be
the
type
you
want
to
return
and
E
the
type
containing
the
error
information
you
want
to
pass.
This
makes
it
easy
for
the
users
to
match
on
it
and
maybe
Panic.
If
the
error
is
severe
or
ignore
it,
it's
a
user's
choice
but
I
think
it's
a
very
good
solution.
A
A
Where
e
is
an
enormous
drug
containing
error
information,
the
end
user
can
match
and
decide
what
to
do
and
there's
also
crates
that
try
to
make
this
easier,
most,
notably
anyhow
in
this
error,
which
I
really
like
I
would
recommend
taking
a
look
at
them.
If
you
are
serious
about
trying
rust
here's
a
code,
an
example
code
of
using
results,
so
we
have
an
error
enum
with
a
function
that
may
or
may
not
return
an
error,
and
at
the
very
bottom
we
have
a
match
statement.
A
What
we
call
the
error
propagation
function,
which
yeah
it
calls
me
error
and
instead
of
directly
matching
on
it,
it
uses
this
question
mark
operator
and
that
question
mark
operator
basically
means.
If
it's
okay,
then
we
evaluate
this
expression
to
the
the
value
contained
in
OK
and
if
not,
we
return
back
the
error,
which
is
really
nice
instead
of
having
to
re
not
throw
up,
but
we
turn
the
results
back
up
and
then
there's
an
example
on
using
unwrap,
which
is
a
very
quick
and
hacky
way
to
develop
code.
A
A
A
If
you
want
to,
for
example,
have
dynamic
code
in,
say
you
want
again
C
plus
plus,
you
want
an
animal,
but
there
may
be
dogs
and
cats.
Well,
maybe
you
just
want
an
animal
that
can
walk.
So
if
you
take
a
box
with
a
dynamic
animal
trait,
this
is
a
fat
pointer
with
v
table
information
and
can
be
used
to
well
dynamically
work
with
objects
matching
in
the
straight
bound.
A
Generics
are
a
way
to
have
function,
structs
and
more
take
any
type
matching
certain
bounds,
so
this
is
also
similar
to
templates
in
a
way
in
three
plus
plus
and
code
is
generated
as
at
compile
time
accordingly
generating
multiple
versions
of
the
construct
for
each
wheel
type
used.
So
if
you,
for
example,
give
the
example
function
an
unsigned,
32-bit,
integer
and
assigned
one
in
two
different
places,
this
function
will
exist
twice
for
the
different
types
in
the
resulting
binary
and
miscellaneous
thing.
A
The
things
that
I
would
have
loved
to
hear
about,
because
I
was
confused
added
us
first
at
first,
as
anybody
of
code
is
an
expression.
The
Taylor
expression
of
the
block
is
what
it
basically
evaluates
to
by
extension.
Functions
do
not
need
a
return
statement,
but
can
simply
place
the
return
value
as
a
Taylor
expression,
which
is
actually
really
cool.
A
It
looks
good,
then
I
quickly
wanted
to
touch
on.
Debug
derives
because
I
did
not
know
this
existed
until,
like
a
month
after
I
started
and
they're
just
really
useful
for
quickly
seeing
the
workings
of
your
binary
without
having
to
attach
a
debugger,
and
with
that.
Thank
you
for
attending
and
if
you
have
any
questions,
feel
free
to
ask
them
foreign.