►
Description
Rust for Non-Systems Programmers by Rebecca Turner
Rust improves on C and C++ by providing memory safety and better concurrency primitives. But for a lot of tools and programs, dynamic languages like Python, Ruby, and Perl are already memory safe and fast enough. “Rust for Non-Systems Programmers” showcases some of the reasons I like Rust as someone who's not a systems programmer, including mutability tracking, development tooling, great documentation, a welcoming community, type-inference/algebraic datatypes, and error handling.
A
A
A
A
And
here's
the
new
website
today
in
mid-2020
now
rust
is
about
empowering
everyone
to
build
reliable
and
efficient
software,
and
the
website
focuses
on
reliability
and
productivity,
but
a
lot
of
the
documentation
is
lagged
behind
and
still
assumes
that
new
rust
programmers
already
know
c,
plus
plus,
or
something
similar
that
made
it
really
hard
for
me
to
learn
rust.
I've
never
really
understood
memory
management,
so
a
lot
of
the
documentation
was
pretty
inaccessible.
A
Before
we
start
writing
code,
let's
take
a
quick
look
at
some
of
the
things.
Rust
makes
strikingly
easy
and
don't
worry
if
I
go
through
these
quickly.
We'll
come
back
to
these
features.
Soon
rust
can
do
command
line
argument,
parsing
generated
from
a
type
definition
with
automatic
typo
correction,
while
generating
tab,
completion,
scripts
and
man
pages
at
compile
time.
A
Rust
can
give
great
error
reports
for
complex
errors,
while
automatically
deserializing
json
to
a
custom
type
and
rust.
Can
output
fancy
test
dips
with
a
one
line
import
that
integrates
with
the
default
test
framework
rest
can
do
a
whole
lot
more
too,
but
I
don't
want
to
just
list
random
rest
features
for
30
minutes
when
I
was
learning
rust,
a
process
that
had
three
or
four
false
starts
since
about
2016
I
kept
getting
halfway
through
writing
a
program
before
I'd
get
stuck
on
a
compiler
error.
A
A
I
have
adhd
and
it
varies
from
person
to
person,
but
one
area
I
really
struggle
with
is
working
memory,
which
is
roughly
how
much
information
you
can
hold
in
your
head
at
once
and
as
an
engineer.
That
means
that
I
can't
hold
much
of
the
program
concept
in
my
mind.
While
I
work
it's
really
important
that
I
have
a
powerful
compiler,
linters
and
tests,
because
otherwise
I
have
no
way
of
knowing
that
the
program
is
correct.
A
Type,
annotations
and
auto
completion
aren't
optional
niceties.
For
me,
it's
essential
that
my
tools
tell
me
which
operations
are
supported
on
which
variables,
because
otherwise
I
have
to
look
them
up
nearly
every
time.
Rest
really
shines
in
all
these
areas.
I
work
with
my
compiler
to
check
my
work
and
it
helps
me
feel
a
lot
more
confident
that
my
programs
do
what
I
think
they
do
before
we
start
looking
at
code.
I
want
to
point
out
a
few
of
the
tools
that
make
writing
rust,
easy
and
fun.
A
A
We
have
two
very
good
language
servers
for
auto
completion
definition,
jumping
quick
fixes
and
more
rls
is
distributed
with
rust
itself
and
rust.
Analyzer
is
a
community
project
and
we
also
have
cargo,
a
package
manager
and
build
system
integrating
with
the
crates.io
package
repository
that
handles
everything
from
dependency
resolution
to
building
documentation,
running
tests
and
benchmarking.
A
A
A
A
We
call
the
var
function
in
the
end:
module
and
assign
the
value
it
returns
to
user
rest
figures
out.
The
type
for
us
and
vare
is
a
result
or
returns
a
result,
so
we
have
to
unwrap
it
which
will
crash
if
there's
an
error,
we'll
talk
about
what
all
that
means
in
a
minute
and
next
we
have
an
if
statement,
which
has
braces
but
no
parentheses,
note
that
we're
comparing
strings
with
equals
equals.
A
So
we
have
operator
overloading,
and
then
we
have
this
print
line
macro
the
exclamation
mark
at
the
end
of
the
name
means
it's
a
macro
and
the
string
literal.
There
is
actually
turned
into
a
series
of
formatting
instructions
at
compile
time
and
the
compiler
checks
that
that
we
have
enough
arguments
and
that
they're
the
right
type.
A
A
A
So
this
type
that
ver
and
ver
returns
is
result
which
isn't
a
noun,
which
means
it's
a
type
that
can
be
one
of
a
number
of
different
things.
It's
also
generic
type.
So
we
can
pick
any
two
types,
t
and
e
and
use
a
result
type
which
can
either
be
an
okay
variant
containing
a
t
value
or
an
error
variant
containing
an
e
value.
A
One
way
we
can
deal
with
that
error
is
by
matching
on
it,
which
is
a
bit
like
an
is
instance
check
here.
We'll
just
handle
an
error
by
printing
a
simple
message.
So
if
we
have
an
okay
value,
we
take
that
and
run
our
logic
from
before.
We
have
an
error
value.
We
throw
it
away
using
the
underscore
as
a
place,
a
placeholder
or
wildcard
and
just
print
that
little
message.
A
So
now,
when
we
run
our
program
within
valid
data,
we
print
an
error
message
instead
of
crashing
we'll
talk
about
some
other
ways
to
handle
errors
as
we
go,
but
for
the
definitive
rundown
check
out,
jane
ludspy's,
talk,
error
handling,
isn't
all
about
errors,
but
this
talk
is
about
ref's
value
as
a
practical
programming
language,
which
means
doing
a
lot
more
than
writing
hello
world.
So,
let's
write
a
program
in
rest
and
explore
some
of
the
ways
the
language
helps
us
out.
A
I
have
this
rear
seat.
Printer
hooked
up
to
my
computer
and
it's
super
fun
to
play
with
there's
no
ink,
so
paper
is
incredibly
cheap
and
they're
designed
for
restaurants
in
retail,
so
they're
incredibly
durable.
I
always
forget
to
check
the
weather
in
the
morning,
so
I
want
to
write
a
program
I
can
set
to
run
before
I
wake
up.
That
tells
me
the
weather
and
how
it'll
feel
compared
to
the
previous
day.
A
A
A
A
So
we
need
to
deal
with
that.
Somehow
note
that
this
isn't
entirely
unique
to
rust,
though
our
python
program
would
also
crash
if
api
kiobj
wasn't
a
json
object
or
if
it
didn't
have
a
key
named
api
key
or
if
the
value
of
that
key
wasn't
a
string
but
rest
makes
us
be
explicit
about
all
these
assumptions
that
we're
making
that's
not
necessarily
a
bad
thing.
A
It
helps
us
figure
out
where
errors
could
happen,
but
it
is
awfully
verbose
and
painful
to
write
like
this,
but
we
do
have
a
better
way
here,
we're
declaring
a
struct
which
is
roughly
a
class
in
the
sense
of
a
blob
of
data
with
named
fields
and
methods
and
then
we're
deriving
some
traits
for
it.
So
what's
a
trait.
A
A
trait
is
a
set
of
method,
signatures
that
specify
some
interface
here.
The
from
trait
lets
us
convert
from
one
type
to
another.
We
can
implement
a
trait
for
a
type
with
an
impul
block.
Note
the
self
keyword
there
that
indicates
the
impul
block's
type
that
makes
refactoring
a
lot
easier
and
lets
us
talk
about
things
like
a
function
that
returns
the
same
type
as
the
value.
It's
called.
A
A
Rust
lets
us
do
a
lot
of
funky
things
with
traits
and
particularly
traits
with
generic
types
like
these
here's,
the
into
trait,
which
is
from
in
the
other
direction
we
can
implement
into.
U
for
all
types
t
as
long
as?
U
implements
from
of
t
the
implementation
is
pretty
simple.
If
you
can
wrap
your
head
around
that,
we
call
the
you.
We
call
use
from
method
and
that's
pretty
magical.
We
only
have
to
implement
one
of
into
or
from,
and
we
get
the
other
implement,
the
other
trait
for
free.
A
So
if
we
have
this
implementation
from
string
for
open
weather
config,
we
can
use
the
into
method
on
the
string
type
to
convert
to
an
open
weather
config
object,
but
about
that
two
owned
call
there.
What's
the
deal
shouldn't
a
string,
literal
already
be
a
string
without
calling
another
method
well
in
rust,
string
literals
get
baked
into
the
compiled
binary
directly,
because
that
data
is
always
sitting
at
a
fixed
location
in
the
library.
A
We
can't
change
it
without
copying
it
into
memory
first,
because
if
we
changed
it
there,
it
would
change
it
for
everyone
else
using
the
string
literal.
So
if
we
want
to
have
a
string
that
belongs
to
us
rather
than
one
referencing,
some
data
elsewhere
in
the
program,
we
have
to
call
the
two
owned
method
to
convert
it,
which
creates
a
new
string,
object
and
copies
the
data
we
need
into
it
back
to
our
open
weather,
config
struct.
A
We
don't
have
to
implement
every
trait
by
hand
like
we
were
doing
within
to
and
from
the
other
option
is
to
use
a
derived
macro,
which
is
a
function
written
in
rust.
That
reads
the
types
definition
as
a
syntax
tree
and
automatically
generates
an
impul
block
for
us,
there's,
usually
a
few
requirements
for
deriving
traits
in
particular
for
traits
like
debug,
clone
and
deserialize.
A
A
A
A
The
next
change
I
want
to
make
is
adding
struct
opt
which
generates
a
command
line
interface
from
a
struct
definition.
Instead
of
declaring
all
our
arguments
as
strings
and
pulling
them
out
of
an
untyped
hash
map,
we
just
declare
them
as
struct
fields,
which
means
we
get
things
like
autocompletion
for
our
command
line.
Options,
along
with
bonuses
like
detecting
that
option
fields
aren't
mandatory
and
vec
fields
can
have
multiple.
A
A
The
next
thing
I
want
to
do
is
add
some
error
reporting,
so
we
don't
have
to
unwrap
everything
and
cause
panics
when
something
fails.
The
error
crate
by
jane
ludsby
gives
us
the
beautifully
formatted
error
messages.
I
showed
off
at
the
beginning
of
the
talk
and
has
a
lot
of
other
functionality
we
won't
explore
here
now
we
can
handle
errors
with
the
question
mark
operator,
which
is
a
pretty
simple
but
important
bit
of
syntax
trigger.
A
The
question
marks
are
transformed
into
roughly
these
match
statements.
If
we
have
an
okay
value,
we
take
that
value
and
use
it.
Otherwise
we
return
the
error
value
from
the
whole
function.
We
just
bubble
up
the
error
to
the
caller.
It's
a
little
bit
like
throwing
an
exception,
but
we
don't
quit
an
arbitrary
series
of
functions.
We
only
go
up
one
layer
and
the
type
system
doesn't
let
us
ignore
it.
A
Using
the
question
mark
operator
again
we're
going
to
use
the
wraparound
methods
from
errors
wrapper
trait
to
more
accurately
describe
what
went
wrong.
We
just
write
a
bit
about
what
we
were
doing
that
might
have
caused
an
error
and
then
that
string
will
get
displayed.
If
the
error
report
is
printed,
it's
a
pretty
simple
step,
provided
you
do
it
from
the
start
and
it
makes
debugging
a
lot
easier.
A
Here
we
can
try
to
use
a
non-existent
file
or
an
invalid
one
as
our
config,
and
we
can
see
the
error
messages
we
get.
These
are
pretty
simple
on
their
own,
but
they're
especially
useful
when
we
have
a
bunch
of
layers
of
error
contacts
to
figure
out
what
we
did
wrong
and,
unlike
exceptions
in
a
lot
of
languages,
we
don't
just
get
an
enormous
unreadable
stack
trace
by
default.
A
A
Off
we
can
see
when
we
pretty
print
the
response
object.
We
get
all
the
fields
we
might
expect,
headers
a
status
code
and
so
on,
and
we
can
also
print
the
response
text,
which
is
this
big
minified
json
blob
we're
going
to
deserialize
that
too,
but
first,
let's
clean
up
our
interface
to
the
open
weather
api.
A
A
Now
we
can
just
read
our
config
config
object
from
the
same
json
file.
We
were
using
before
without
even
a
constructor
method.
Now
to
make
our
api
a
bit
cleaner,
let's
start
implementing
methods.
This
gives
us
something
that
looks
a
lot
like
the
classes
we
may
have
used
in
other
languages
and
although
rust
doesn't
have
inheritance
or
subtyping
generic
functions
and
creates,
can
get
us
pretty
close.
A
A
Here
we
have
one
generic
parameter
named
response
and
the
colon
indicates
a
trait
bound,
which
means
that
response
needs
to
be
a
type
with
an
implementation
of
d
serialize
owned,
which
is
exactly
what
derived
d
serialize
gives
us.
Essentially,
we've
copied
a
type
parameter
from
the
30.json
from
reader
functions
so
that
we
can
deserialize
to
any
type
we
define.
A
A
Here's
that
constructor
function,
which
takes
two
floats,
calculates
their
difference
and
matches
them
to
the
correct
temp
difference
variant.
We're
also
adding
conditional
statements
to
the
match
patterns,
which
makes
it
help
which
helps
make
it
a
bit
clearer
that
we're
determining
which
range
the
delta
is
in
I'm
really
bad
at
arithmetic
stuff.
So
I
want
to
write
a
few
tests
to
make
sure
I
got
the
subtraction
order
and
everything
right.
A
First,
we
have
this
config
test
attribute,
which
means
the
entire
test
module
is
conditionally
compiled,
so
our
tests
don't
get
lumped
into
our
other
builds.
We
have
to
import
the
functions
and
values
from
the
parent
module.
That
is
the
rest
of
the
file
explicitly
and
then
a
test
is
just
a
function
annotated
with
the
test
attribute
and
finally,
we
can
write
asserts
with
the
assert
and
assertiq
macros.
A
We
can
run
our
tests
to
make
sure
that
we've
written
everything
correctly
and
another
little
thing
I
like
about
rust.
The
type
system
lets
me
describe
and
check
a
lot
of
my
code
before
it
compiles
correctly.
So
I
end
up
writing
tests
that
crash
and
fail
immediately
a
lot
less
often
than
I
do
in
other
languages,
which
is
a
big
boost
to
my
self-esteem.
A
Let's
implement
the
default
trait
for
stats,
which
gives
us
a
way
to
construct
a
default
value
for
a
type.
It's
like
go's
concept
of
a
zero
value,
but
rest
doesn't
require
that
every
type
implement
default
because
that's
not
always
meaningful.
For
example,
types
like
file
handles,
don't
have
a
reasonable
default,
we're
picking
infinity
for
the
starting
minimum
value,
because
every
float
is
less
than
infinity
and
negative
infinity
for
max.
A
From
the
same
reason,
note
that
we
have
associated
constants
for
even
our
primitive
types
in
rust,
primitive
types
are
treated
just
like
any
other
type,
as
opposed
with
like
java,
where
we
have
to
treat
reference
types
and
primitive
types
really
differently.
A
A
A
To
finish
up,
let's
print
out
the
data
we've
gathered
first,
I
want
to
print
a
smiley
face
for
good
weather,
so
I'll
check
if
the
average
temperature
today
is
between
60
and
80
degrees,
then
we'll
print
the
first
line
truncating
today's
average
temperature
to
two
decimal
places
and
then
we're
going
to
print
the
rest
of
it.
There's
a
bunch
to
break
down
here.
So,
let's
break
it
down
first,
because
print
line
is
a
macro.
We
can
do
weird
things
with
the
syntax.
Like
this
keyword
argument,
syntax,
that's
only
used
for
the
printing
and
formatting
macros.
A
Next,
we
have
a
match.
Statement
rests
if
else
and
match
statements
return
a
value,
so
we
can
use
them
in
line
like
this
for
argument,
values
and
then
we're
going
to
finish
with
a
smiley
face.
If
today
is
going
to
be
warm
and
nice
weather
or
a
period
otherwise,
and
after
printing
all
that
information
out
our
program
is
done.
A
A
A
I
certainly
couldn't
have
learned
rest
on
my
own
and
as
long
as
you're
respectful
of
your
peers,
we're
all
glad
to
help
everything
I
talked
about
is
just
a
tiny
portion
of
what
you
can
do
with
rest
and
what
rest
can
do
for
you
there's
so
many
features
and
tools.
I
wanted
to
talk
about
that.
I
didn't
have
time
for
things
like
adding
methods
to
foreign
types
type,
safe
numbers,
unit,
conversions
and
more
thanks.
So
much
for
listening,
and
I
hope
you
do
some
amazing
things
with
rest.