►
From YouTube: RustLatam 2019 - Kevin Hoffman: WebAssembly with Rust
Description
WebAssembly fulfills the long-awaited promise of web technologies: fast code, type-safe at compile time, execution in the browser, on embedded devices, or anywhere else. Rust delivers the power of C in a language that strictly enforces type safety. Combine both languages and you can write for the web like never before!
In this demo-heavy talk Kevin will take us on a journey from the basics of WebAssembly to using WebAssembly to integrate with JavaScript, build complete websites, and even host and interpret in Rust apps.
He'll even show hot-swapping WebAssembly modules to control LEDs on a Raspberry Pi.
Follow us on Twitter: https://twitter.com/rustlatamconf
A
We'll
see
I'm
also
not
a
front-end
guy,
so
I
want
to
set
the
bar
really
low
I,
don't
have
fancy
animations
or
any
of
the
really
good
stuff
that
the
previous
presenter
slides
had
so
I
would
I
would
do
this
all
from
a
terminal
window
if
they
let
me,
but
so
I've
been
using
rust
for
about
two
years
off
and
on
I
just
recently
finished
a
web
assembly
book
that
uses
rust
my
day.
Job
is
pretty
much
all
go.
A
I'm
a
huge
elixir
fan
and
I
will
take
a
few
seconds
just
to
troll
the
previous
presenter,
about
OTP
having
less
than
10
microseconds
called
start
I'm
just
saying,
and
then
I'm
also
like
I
said:
I'm
a
back-end
guy
distributed
systems
are
what
I
do
the
less
user
interface
the
better
for
me.
So
it
makes
me
talking
about
web
assembling
a
little
interesting.
A
So
what
I
want
to
make
sure
that
you
get
out
of
this
is
some
hopefully,
some
curiosity
about
what
web
assembly
is
and,
more
importantly,
where
you
should
and
shouldn't
use
it
did
anybody
go
to
the
workshop
yesterday
on
the
web
assembly?
Ok,
a
couple
other
than
the
the
references
to
web
assembly
that
you've
had
here
how
many
people
are
familiar
with
web
assembly
already?
A
And
again
this
is
a
lot.
A
lot
of
this
comes
from
me
being
a
back-end
guy,
but
I
want
to
kind
of
focus
on
the
idea
that
whether
sembly
isn't
just
a
brand
new
way
of
doing
JavaScript,
it
isn't
a
JavaScript
compiler
or
just
another.
Fancy
flavor
of
typescript
and
I
personally
think
calling
it
web
assembly
and
having
the
web
name
in
front
of
it
is
doing
the
technology
a
disservice
and
again
so
hopefully,
you'll
be
you'll.
A
This
is
a
fairly
opinionated
slide,
born
of
my
hatred
of
front-end
development.
What
what
we
have
with
web
development
today
is
a
lot
of
fragmentation.
We
have
to
deal
with
browser
compatibility.
We
have
to
deal
with
different,
build
environments,
typescript
Java
scripts,
all
the
other
scripts,
the
bigger
our
applications
are
getting
bigger,
they're
getting
slower,
I'm
sure
we
all
use
slack.
A
It's
as
R
as
the
web
becomes
more
powerful
humans
expand
to
fill
whatever
space
they're
given
and
we're
doing
the
same
thing
with
our
web
technology
and
so
the
more
power
we
have,
the
more
power
we
waste
and
I
think
there's
a
better
way
to
do
it,
not
a
not
a
better
way
to
waste
power,
but
a
better
way
to
build
applications
and
as
a
back-end
guy,
the
just
the
amount
of
tooling
and
setup
that's
necessary
to
even
get
a
basic
hello
world
running
on
the
web.
Now
is
it's
just
ridiculous.
A
The
the
node
modules
directory
needs
to
go
away
and
I
think
that
web
assembly
can
get
us
there.
It's
certainly
not
going
to
replace
JavaScript.
Sadly,
it's
not
going
to
replace
node
or
the
node
modules
directory,
but
hopefully
it'll
give
us
a
way
to
get
some
of
the
benefits
of
you
know
the
the
Russ
language
and
bring
those
to
the
front
end
and
the
back
end
as
well.
A
A
The
webassembly
is
safe
and
isolated
and
its
memory
is
in
a
sandbox
I'll,
get
to
security
and
hopefully
again
controlling
the
previous
presenter
of
about
how
secure
webassembly
can
be
and
in
a
couple
slides.
But
one
of
the
important
things
here
is
that
you
can
compile
to
webassembly
from
any
of
the
supported
languages
and
when
I
started.
Writing
the
web
assembly
book.
That
was
essentially
one
length
with
two
languages:
Rustin
C
or
C++.
And
now
you
can
do
C
C++
rust
go
there's
a
couple
of
other
ways.
You
can
do
it.
A
You
can,
for
whatever
reason,
compile
JavaScript
into
web
assembly
I'm,
not
really
sure
what
niche
that's
trying
to
fill.
But
it's
possible.
You
can
then
interpret
web
assembly
in
dozens
of
different
languages
and
I
think
this
is
the
more
important
part
that
well
we
all
just
assume
that
web
assembly
has
a
runtime.
So
we
think
the
browser
or
the
v8
engine-
that's
just
one
of
many
possible
runtimes
and
it
just
happens
to
expose
a
JavaScript
API
go,
can
host
and
run
web
assembly
modules
so
can
rust
so
can
see.
A
When
you
leave
here
and
you
just,
you
immediately
feel
the
need
to
google
web
assembly
technology
there's
a
couple
of
key
words
that
you
shouldn't
you
can
search
for
I'm,
just
trying
to
save
you
on
open
tab
space
on
the
browser
here.
The
module
is
the
portable
binary
format.
It's
the
web
assembly
file
that
dot
Wazza
mcleod
web
assembly
has
concept
of
tables,
and
at
the
moment
the
tables
are
only
there
to
will
allow
us
to
do
function.
A
Mapping
I
think
the
spec
has
more
room
for
advancement
there,
but
it's
not
really
an
area
that
I've
dug
and
much
into
linear
memory,
just
big
blocks
of
arrays
and
that's
where
that's
how
webassembly
accesses
its
internal
data
and
in
the
browser
you
can,
you
can
give
webassembly
a
linear
memory
or
you
can
take
it
from
the
web
assembly
module
so
depending
on
how
you
want
it
set
up.
You
can
choose
to
share
memory,
and
this
goes.
Some
of
this
goes
to
security.
A
Webassembly
can
only
access
the
memory
that
you
tell
it.
It
can
access.
So
it's
only
as
secure
as
the
host
environment
and
admittedly
javascript
has
a
number
of
ways
to
be
exploited.
But
if
you're
running
web
family
in
a
more
tailored
fit
environment,
then
you
can
make
it
as
as
secure
as
you
want.
A
trap
is
just
essentially
webassembly
terminology
for
handling
an
exception
and
imports
and
exports
are
the
two
most
important
things
that
webassembly
does.
Imports
refer
to
the
host
environment,
feeding
webassembly
hooks
so
that
it
can
do
things
and
then
exports
involved.
A
It
refers
to
web
assembly.
The
web
assembly
module
exporting
functions
so
that
they
can
be
called
by
the
host
web
assembly
has
four
data
types
and
that's
it
and
I.
Just
I
assume.
We
all
sort
of
knew
this,
but
I
want
to
point
out
that
all
of
the
other
fanciness
that
we
see
sitting
on
top
of
web
assembly
is
smoke
and
mirrors.
It's
all
generated
code
being
able
to
compile
Doom
and
run
it
in
web
assembly
while
fun
and
a
great
way
to
spend
a
day
at
work.
Is
all
code
generation.
A
A
So
why
do
we
want
to
use
webassembly
other
than
just
the
fact
that
it's
new
and
shiny
and
that's
what
we're
attracted
to
for
me
I?
Think
one
of
the
biggest
reasons
is
portability.
We
have
we've
always
been.
We've
been
given
this
promise
of
write
once
run
anywhere
since
the
beginning
days
of
Java,
and
we
didn't
get
what
we
were
promised
dotnet.
A
The
the.net
framework
promised
that
we
didn't
get
that
either
dotnet
core
is
closer
than
Java
was,
but
it's
still
not
really
the
the
vision
of
having
this
Universal
binary
format
that
anything
can
execute
and
I.
Think
webassembly
actually
gives
us
a
chance
at
finally
having
that
web
assembly
is
fast,
the
through
some
details
about
how
the
virtual
machine
works
and
how
fact
machines
work.
A
A
Web
assembly
is
secure,
like
I
said
it
it's
as
secure
as
its
host
environment.
You
can
secure
the
memory
so
that
it
so
that
it
can't
be
tampered
with.
You
can
secure
the
web
assembly
module
itself.
The
spec
has
room
inside
the
binary
file
for
I
forget
what
the
is
called.
Maybe
just
metadata.
You
can
add
a
digital
signature
to
the
file
so
that
you
can
verify
that
you
own
or
you
produced
that
file.
A
A
You
know,
weather
sembly
format
was
specifically
designed
for
download
over
the
web,
and
it
is
surprisingly
small
I
actually
meant
to
put
portable
here
twice,
just
because
I
wanted
to
harp
on
that.
One
point
and
webassembly
is
largely
language
agnostic.
As
long
as
you
build
something
that
can
create
a
binary
that
conforms
to
the
spec,
it
doesn't
make
any
difference
what
language
you
wrote
it
in
and
it
doesn't
make
any
difference
what
language
is
running.
A
Does
anybody
really
need
me
to
go
into
why
we
want
to
use
rush
for
this?
I
do
run
into
this
problem
when
talking
to
different
people
who
aren't
at
a
rest
conference
and
confidence
safety
performance,
one
of
the
things
that
I
think
people
don't
give
rust
enough
credit
for
is
the
expressive
nature
of
the
language
itself.
In
many
cases,
when
porting
code
from
go
to
rust,
I've
actually
had
the
code
become
more
readable,
not
less.
A
A
So
I
was
looking
for
an
analogy
for
what
webassembly
is,
and
you
know
Fineman
has
had
this
saying
where
you
don't
really
know
a
subject,
unless
you
can
explain
it
in
very
simple
terms,
and
so
for
me,
web
assembling
is
portable
brains.
I
can
take
the
brain
out
of
one
thing
and
put
it
into
another
and
assuming
the
those
two
things
all
share
the
same
set
of
appendages,
it
should
just
work,
so
one
of
my
brains
could
be
running
inside
kubernetes
as
an
open,
fast
function
which
I've
actually
gotten
working.
A
A
Maybe
it's
a
drone
and
put
it
into
a
test.
Harness
and
I
could
literally
run
simulations
for
this
drone.
You
know
what
I
could
run
it
in
a
build
pipeline
through
an
automated
test
or
I
can
run
it
on
the
physical
device
and
I
can't
think
of
any
other
technology,
whether
it's
Java
at
core
or
anything
else.
It
gives
me
that
type
of
portability
I
could
write
it
all
in
C,
but
no
one
wants
to
do
that.
A
We
all
need
to
know
what
people
keep
telling
me
to
stop
showing
the
ugly
web
assembly
code,
because
it's
it's
definitely
not
not
pretty,
but
I
think
we
should
know
like
the
fact
that
whether
somebody
only
has
four
data
types
and
the
fact
that
what
assembly
can't
do
anything
that
the
hosts
won't.
Let
it
do.
A
A
A
You
can
only
do
and
you've
got
exports,
so
this
makes
this
function
called
add
available
to
the
host,
and
so,
if
my
host
is
JavaScript,
I
can
run
this
function
and
you
can
see
there's
some
JavaScript
here.
This
is
just
straight-up,
regular
JavaScript,
it
just
happens
to
be
compatible
and
I
believe
most
modern,
browsers
all
support
the
the
web
assembly
standard.
So
you
should
be
able
to
run
this
anyway.
A
So
basically
we
just
we're
loading
the
binary
file
up
and
then
we're
using
the
JavaScript
web
assembly
class,
and
you
can
think
of
this
as
yet
one
of
many
runtimes.
This
webassembly
that
is
instantiate
is
the
JavaScript
runtime
for
hosting
a
web
assembly.
Module
and
I'll
show
a
rust
at
one
time
for
hosting
what
assembly
module,
but
you
know
if
I
were
to
run
this
on.
You
know
web
browser.
You
would
see
this
on
the
console
and
it
all
just
looks
as
you
would
expect.
A
But
the
point
here
is
that
anything
beyond
what
you
see
here
and
the
ugly
webassembly
that
I
just
showed
is
all
code
generation
and
whether
it
was
compiled
by
rust
or
go.
It's
all
going
to
end
up
at
least
today,
you're
looking
at
something
like
this
and
when
as
the
web
assembly
spec
grows
and
we
get
more
potentially
more
data
types
or
more
robust
ways
to
share
data
with
the
host.
Then,
theoretically,
our
shins
will
shrink,
but
our
development,
while
our
developer
experience
gets
better.
A
A
A
We
just
build
it
as
a
web
assembly
module
and
we
could
copy
this
file
into
our
directory
and
run
the
same
thing
from
web
assembly
or
from
JavaScript
and
prove
that
we
get
the
same
results.
I
don't
expect
to
have
a
much
spare
time
so
I'll
just
I'll
skip
that
demo
and
you
can
just
sort
of
I'll
wave
my
hands
and
you
can
accept
that
that
stuff
works.
A
So
it's
been
mentioned
a
couple
times
today,
as
well
as
yesterday
during
the
workshop
that
wasn't
by
Jen,
is
using
macros
to
generate
a
whole
bunch
of
code,
and
hopefully
now
you've
got
a
little
bit
of
perspective
on
what
exactly.
Why
isn't
bind
Jen
is
doing
when
it's
generating
the
code
at
a
low
level.
It's
adding
functions
to
your
web
assembly
module
that
can
then
be
called
again
by
the
Weizmann
by
Jen
COI
to
give
it
the
metadata.
A
A
So
the
the
two
things
that
that
generally
people
use
that
get
the
biggest
reaction
in
JavaScript
integration
is,
you
can
import
JavaScript
that
so
that
when
it's
imported,
it
just
looks
and
behaves
like
it's
regular
rust
and
you
can
export
native
rusts
so
that
it
appears
as
though
it's
just
its
regular
JavaScript
and
the
real
power
of
this
library
is
how
seamlessly
it
bridges
that
gap
between
the
two
so
that
when
you're,
looking
at
JavaScript
you're,
not
thinking.
Oh,
this
JavaScript
came
from
rust.
Like
some
other,
you
know,
transpiling
libraries
tend
to
do.
A
They
have
some
of
these
weird
after-effects
and
again,
whereas
mine
Jen
generates
a
bunch
of
these
javascript
shims
to
allow
your
to
talk
to
JavaScript,
Jayesh,
sis
and
web
sis
are
just
essentially
crates
that
defined
things
that
you're
going
to
need
to
talk
to
JavaScript.
So
your
basic
JavaScript
primitives
because
functions
like
console
log
web
sis
has
the
bindings
that
you
need
in
order
to
traverse
the
DOM
and
the
manipulation
access.
A
Some
of
the
other
functionality
like
WebGL
audio,
has
anyone
who
seems
a
SS
before
use
this
a
couple
you
know,
essentially,
you
can
think
of
it
as
you've
got
this
JSS
crate,
prefix,
and
then
inside
that
crate
you
have
access
to
rust,
functions
and
native
rust
structures
that
will
eventually
do
their
JavaScript
equivalents.
So
this
will
actually
call
the
JavaScript
date
now
function.
A
A
So
one
of
the
other
libraries
that
you're
so
raise
your
hand
if
you
actually
do
front-end
development.
I
know
it's
rare,
but
you
know
if
you
do
front-end
development.
So
if
you're
planning
on
doing
if
you're
planning
on
exploring
web
assembly-
and
you
want
to
build
a
user
interface,
you
had
oh
it
to
yourself
to
go.
Look
at
a
library
called:
u
ye
w!
A
It's
a
rush
native
library
that
gives
you
a
react.
Redux
style
set
of
message
passing
in
order
to
control
a
virtual
Dom
and
it
all
compiles
into
web
assembly,
and
if
I,
have
to
do
front-end
web
development,
doing
it
in
rust.
Isn't
such
a
bad
thing!
So
how
many
have
you?
How
many
have
hosted
a
webassembly
module
in
rust
all
right?
Well,
you
guys
need
to
stop
raising
your
hands
because.
A
So,
as
I
said,
I
am
obviously
biased
towards
back-end
development
and
distributed
systems
and
cloud
and
so
being
able
to
host
the
web
assembly.
Module
in
rust
is
where
I
think
some
of
the
real
power
comes
from,
not
just
because
I
like
hosting
stuff
and
rust,
but
because,
if
rust
can
host
it,
then
so
too
can
so
many
other
things
like
I
said
we
don't
currently
have
a.
A
We
don't
have
a
tool
that
generates
all
the
magic
smoke
and
mirrors
that
we
do
for
JavaScript.
So
a
lot
of
this
stuff
is
still
a
little
rough
around
the
edges.
There
was
a
crate.
There
still
is
a
crate
called
Waze
me
I'm
sure
it's
got
a
better
pronunciation
than
that,
but
it
came
out
of
I
think
parodies
work
with
blockchain
and
they
were
using
it
for
blockchain
contracts
and,
as
a
result,
the
developer
experience
isn't
designed.
For
you
know
what
I
would
consider
just
common
everyday
use.
A
A
So,
like
I
said,
you
can
use
it
for
service
embedded,
IOT
micro
services
being
able
to
use
web
assembly
modules
everywhere
that
used
to
be
able
to
use
a
land
or
a
cloud
function.
Who's
pretty
appealing,
I
mentioned
briefly
that
you
can
sign
the
module
so
that
in
your
production
environment,
you
can
guarantee
that
a
particular
webassembly
module
came
from
who
says
it
came
from
and
can
do
what
they
claim.
They
can
do.
A
So
I've
got
a
sample
here.
That's
just
a
rust
application
that
runs
a
that
runs.
It
interprets
a
web
assembly
module,
so
the
module
just
does
its
got
a
functional
that
logs
a
string
from
inside
the
web
assembly
module.
So
this
is
an
export
and
then
there's
a
function
that
will
be
exported
called,
do
work
and
these
imports
and
exports
operate
the
same
way
as
they
would.
A
You
know
I'm
just
obviously
I'm
just
hacking
around
to
grab
the
bytes.
You
would
get
them
from
disk
or
you'd
get
them
injected
through
a
network
call
in
some
sort
of
service
environment.
There's
all
sorts
of
ways
you
could
get
these
bytes
loaded
into
memory,
but
this
section
right
here
is
essentially
where
all
of
what
most
of
the
web
assembly
magic
happens.
The
setting
the
imports
is
explicitly
telling
your
web
assembly
module
what
it
can
and
can't
do.
If
it's
not
in
this
import
list,
then
your
web
assembly
module
can't
do
it.
A
A
The
only
way
it's
happening
is
through
something
like
this,
and
it's
because
we're
getting
so
much
of
that
JavaScript
generated
for
us
that
we
just
kind
of
take
it
for
granted
and
who
has
heard
of
Wasi
or
was
aware
that
the
the
recent
announcement-
okay,
so
not
too
many
so
right
here,
I
have
a
function,
that's
being
exported
and
it
has
a
name
called
blog
stir.
That's
obviously
proprietary
and
only
works
on
my
samples.
A
I
lose
portability
when
I
take
this
module
out
of
my
rushed
host
and
try
and
run
it
somewhere
else
where
I
don't
get
the
logs
they're
import.
So
what
Wasi
is
trying
to
do
is
define
a
set
of
standards
that
can
be
injected
into
the
imports
of
a
web
assembly
module
so
that
we
do
have
portability.
If
we
have
like
Wasi
core,
we
should
be
able
to
assume
that
we'll
be
able
to
print
a
standard
out
from
our
web
assembly
module
or
read
for
read
from
a
file
or
make
a
network
call
and
along.
A
A
A
A
The
main
point
is
webassembly:
is
it's
a
great
new
technology?
It's
still
early
days,
so
there's
still
some
rough
ideas
around
it
and
the
direction
is
a
little
unclear,
but
I
think
it
has
a
promising
future,
especially
with
rust.
But
it
isn't.
A
hero,
running
webassembly
everywhere
doesn't
make
sense,
so
I
think
the
next
steps
for
all
of
us
is
to
just
figure
out
where
it
makes
sense
to
run
these
web
assembly
modules
and
in
what
runtimes
we
should
be
running
them.