►
From YouTube: zvariant: A Cool New Crate You Shouldn't Use Yet
Description
From the Rust Berlin's January "Rust and Tell" Meetup (https://www.meetup.com/Rust-Berlin/)
Andrés Casablanca: https://twitter.com/castarco
Hosted at Prisma: https://www.prisma.io/
🎥 Filmed by iStream: http://www.istream.pl/
A
First
of
all,
Who
am
I
for
those
who
know
no,
no,
my
name
is
ian
ellie
and
I
I'm
a
bit
of
a
nomad
from
different
countries
and
lived
in
different
countries
and
have
passports
of
different
countries
stuff
and
licenses
from
different
countries.
It's
a
lot
of
fun.
These
damager
me
work
for
this
small
company
called
red
hat
and.
A
And
so
a
bit
of
background
I
give
a
talk
about
this
topic,
a
trust
fast
and
and
also
in
this
Meetup
like
many
months
ago,
but
at
that
time
I
hadn't
made
a
lot
of
progress
yet
so
so
background.
For
some
a
bit
of
recap
for
others,
I
started
this
project
called
zaebis.
It's
not
called
zebras
is
called
zebras
browser
correctly,
please
and
what
it
does
is
like
it's.
A
Debus
great
Debus
is
a
very
efficient
binary
inter
process
communication
protocol.
A
It
was
designed
for
desktop
computers,
but
it's
also
used
a
lot
and
embedded
and
I
think
these
days
it's
used
in
embedded
a
lot
more
than
a
test.
Well
actually
yeah.
As
far
as
I
know
and
I,
don't
see
why
not
it's
very.
If
it's
a
binary
protocol
and
it
has
a
wire
format
like
how
you
what
format
you
are,
you
can
communicate
with
Debus
it's
a
specific
format
and
that
format
is,
as
I
said,
efficient.
So
it
was
used.
A
It
was
used
by
other
projects
as
well
like
outside
of
Debus
context,
and
they
call
it
G
variant.
It's
called
G
variant
because
it's
the
first
API
that
was
provided
was
by
G,
Lib
and
G.
Live
has
like
always
puts
2
G
in
front,
like
I
put
Z
in
front
of
my
perspective,
G
in
front
of
everything.
So
but
as
well.
Almost
it's
not
exactly
the
wire
format
of
Debus.
They
made
some
changes
to
make
it
more
efficient.
A
The
hope
I
think
was
that
those
changes
will
be
put
back
in
the
D
bus
back
and
the
demos
will
change.
But
by
that
time
he
was
a
spread
so
much
changing.
This
pack
was
too
much
of
a
hassle,
and
that
was
too
much
disruption.
So
G
variant
is
slightly
different
from
from
Debus
format,
but
it's
still
based
on
the
same
format
and
stuff,
but
it's
used
a
lot.
For
example,
if
you
have
heard
of
this
cult
or
the
software
called
OS
tree,
it's
used
in
cloud
a
lot
in
these
days.
A
Cloud
infrastructure,
world
openshift
depends
on
it
in
many
different
ways
and
it's
it's
a
bunch
of
G
variant
in
in
files.
The
way
it
stores
objects
also
flat-pack
I'm
not
going
to
go
into
details
of
what
that
is,
but
check
it
out.
It's
also
uses
the
G
variant
and
then
there
is
ad
account,
which
is
a
configuration
database,
simple
configuration
database
and
it
also
uses
this.
A
So
a
lot
of
uses
for
this
format,
G
variant,
so
I
decided
that
it
would
be
very
useful
for
those
people
to
use
to
have
a
separate
crate
for
that
format
only
regardless
of
whether
they
want
to
use
D
base
or
not
so,
and
it's
before
I
could
do
dizzy.
Bus
I
had
to
implement
this
anyway
for
for
my
project,
so
I
started
working
on
this
I
named
it
well.
Zbyszko
Z
variant,
but
I
have
to
explain
a
bit
to
you.
What
the
format
is
before
I
can
continue
about.
A
Crystalline
talk,
it's
it
defines
there's
a
spec,
a
defines
the
data
types
it
allows
and
the
encoding
and
it
uses
natural
alignment.
Yeah
I,
don't
know
if
it
does
ever
know
what
alignment
means.
Memory,
alignment,
okay!
Well,
that's
that
lease
so
there's
some
architects,
CPU
architectures
that
can
only
read
from
aligned
data.
So
you
there,
if
they
want
to
read
data
from
memory,
it
has
to
be
aligned
to
specific
sizes,
for
example,
let's
say
8
bytes
or
4
bytes
or
whatever
the
CPU
says,
and
in
cases
of
other
CPUs,
it's
just
more
efficient.
A
If
you
keep
your
data
aligned,
it's
very
efficient
for
the
CPU
to
fetch
and
write
data
to
memory,
and
because
of
that,
Debus
has
memory
alignment
rules,
but
they
are
very
natural.
I'll
show
you
that
example
later
and
all
the
data
types
have
a
signature.
So
all
the
basic
types
it
defines
there
is
like
one:
it's
a
string,
but
all
the
basic
types
they
have
like
one
character
that
represents
which
what
data
it
is
and.
A
Four
basic
types:
it's
like,
for
example,
for
u8,
it's
y4i,
16,
it's
T,
I,
think
and
stuff
like
that
for
us
for
string,
it's
as
and
all
the
basic
types
of
Rusted
just
changes
map
very
well
to
to
the
deepest
types.
Fortunately,
for
me
and
then
there
is
containers
which
is
not
so
easy,
but
some
are
like
a
rape
and
structure
which
we
have
this.
A
Those
concepts
in
and
rest
of
course-
and
it
is
this
a
dictionary
type
and
the
most
annoying
one
is
a
variant
because
sometimes
you
have
to
pass
data
that
is
dynamically
typed.
So
you
you
specify
at
runtime
what
it
is
you
don't
know
beforehand,
for
example,
there's
an
interface
on
a
diva's
standard
interface
like
if
you
implement
any
service
and
Debus.
You
have
to
implement
this
interface,
which
is
called
properties.
So
you,
the
one
of
the
method,
is
called
get
properties
where
you
give
all
your
properties
and
of
course,
properties
could
be
of
different
types.
A
So
how
do
you
return
an
array
of
varying
types
of
data?
So
what
you
use
is
a
variant.
So
did
it's
for
abused
cases
like
that,
but,
of
course
it
makes
a
bit
life
bit
harder
because
it
dynamically
give
I'll
give
you
some
example
of
how
the
encoding
is.
Don't
love
on
my
graphing
skills.
This
is
the
first
time
I've
ever
made
diagrams
for
my
slides.
A
So
let's
say:
there's
a
string
called
just
say
hello:
you
want
to
put
it
encode
it
in
this
format,
very
easy.
You
have
to
encode
the
length
of
it
and
you
have
to
encode
the
data
itself.
It's
like
just
the
data
like
the
characters
of
your
string,
unicode
string
and
a
null
byte.
That's
it
now.
Byte
is
not
very
useful
for
rust,
but
it
has
to
be
there
and
fun
thing
yeah.
The
null
byte
is
not
included
in
the
size
of
the
the
length.
As
you
can
see,
it
says:
5,
it's
nothing
say
6.
A
We
will
talk
about
this
later
and
the
as
I
said
alignment
is
based
is
natural.
So
since
the
length
of
the
string,
which
is
the
first,
which
is
the
fixed
size,
the
start
of
the
string,
it's
4
bytes,
so
the
alignment
for
4
bytes
is
4
bytes.
So
in
here
in
the
bottom
below,
you
will
see
that
I
have
made
the
numbers
bigger
for
the
for
the
for
the
4
byte
boundaries.
A
So
there's
this
number
like
it's
0
base,
so
on
number
7
you
have
the
memory
address
7,
you
have
the
boundary
for
the
first
byte.
So
since
we
want
to
start
with
a
0
with
a
on
a
4
byte
boundary,
we
first
put
2
zeros
and
then
that's
the
padding
and
then
so.
This
is
the
whole
encoding
of
your
string
and
that's
how
encoding
works
and
in
this
format.
A
Similarly,
the
same
thing,
but
we
put
in
a
variant
just
to
demonstrate
variant
because
I'll
have
problems
with
that
later.
I'll
show
you
a
bit
more
complicated
but
similar
concept
that
you
have
the
data
at
the
end.
That's
the
same
thing:
the
land,
the
string,
the
same
0
byte
and
what
you
do
is,
instead
of
since
you
don't
know
the
type
of
the
data
beforehand,
it's
dynamically
typed,
as
I
said.
So
how
do
people
who
need
to
parse
this?
How
would
they
know
what
type
it
is?
A
So
it's
fine,
so
yeah,
it's
and
as
I
said,
it's
an
efficient
format,
so
they
made
it
in
like
not
four
bytes
but
one
byte
and
then
the
actual
byte,
the
string
type.
So
it
says,
and
then
the
null
byte
in
here
as
well
and
then
the
padding
and
then
the
rest
is
exactly
the
same
as
before
so
I
started.
Working
on
that
the
good
cool
I
had
was
super
efficient
API
I
want
to
have
it
as
efficient
as
possible.
A
A
A
You
you
will
need
lifetimes,
and
the
thing
is
that
it
will
be
like
me:
I,
learn,
trust
and
I've
kind
of
avoided
lifetimes
and
learnt
everything
else,
and
then,
when
I
had
to
deal
with
lifetime,
that
I
was
like
what
am
I
supposed
to
be
like
it's
all
of
a
sudden,
I
felt
like
I,
don't
know
anything
about
trust
anymore,
so
yeah
learn
them.
It's
they're,
not
as
difficult
as
the
sound
in
the
beginning,
and
it's
like
anything
you
can
learn
everything.
A
A
Variant
representation
was
a
challenge,
we're
challenging.
As
I
said,
it's
dynamically
type
and
I
want
everything's.
You
know
it's
a
statically
typed
language,
so
it
wasn't
so
easy,
but
I
went
with
in
the
end.
After
of
a
lot
of
trials
and
errors,
I
went
with
them,
ennum,
which
I
should
have
started
with.
A
But
eventually,
things
started
to
look
good
and
I
had
a
from
beginning,
I
did
test
cases
and
yeah,
they
started
to
pass
and
pass,
and
there
was
more
and
more
data
types
I
could
had,
and
but
at
the
end
of
everything,
I
I
did
hashmap
the
the
dictionary
type
and
the
test
cases
when
I
added
them.
They
were
failing
in
the
beginning
and
I
was
like.
What's
going
on
so
I
first
thought.
The
test
case
is
bad
or
my
code
is
bad
and
everything
was
fine.
The
dictionary
implementation
was
fine.
A
A
Similarly
to
the
string
type
you
have
in
array.
You
also
have
the
the
length
for
battle
of
length
and
then
the
LM
padding
for
the
first
element
and
and
then
you
have
the
data,
the
first
element,
second
and
even
third
element.
Of
course.
It's
all
so
needs
the
same
kind
of
alignment
as
the
string,
because
the
four
bite
length
in
the
beginning-
and
since
it's
in
a
variant
as
I
said,
you
have
to
provide
the
signature
just
before
it
so
there's
the
signature
is
for
arrays
and
T's
the
actual
type,
which
is
64-bit
integer
right.
A
There's
a
reason.
I
showed
you
this,
so
don't
hit
me
first,
so
I
couldn't
figure
out
what
what's
wrong
with
this
picture.
There
is
something
wrong
in
this
picture
so
as
today
we
won't
have
any
quiz.
Let's
have
this
as
a
quiz.
If
anyone
can
point
to
me
what
the
problem
is
here,
I
will
give
you
one
beer
wait,
wait,
wait
first,
here
is
then
no
signature.
Okay,
sorry
I
didn't
mention
this
before
so
good.
That
you
pointed
out
since
signature
is
the
length
of
signature.
A
B
A
B
A
Yeah
the
area
they
need
to
be
so
the
64-bit
integer
needs
to
be
aligned
on
64
bits
like
8
bytes.
So
that's
why
the
padding
it
starts
on
the
16th
okay.
So
nobody
knows
so.
I
continue
anyway.
So
I
couldn't
give
a
figure
out
four
days
right
and
I
was
like
my
girlfriend
was
saying.
Why
are
you
so
sad
these
days?
A
I,
try
to
explain
so
back
to
D
was
back
reading
and
also
reading
the
bytes,
like
I,
was
printing
out
all
the
bytes
and
looking
at
each
and
every
bite,
and
so
first
my
first
I
first
thought
like
it's.
The
padding
I
read
this
back
and
the
more
I
read
it.
I
started
to
get
this
impression.
That
I
was
wrong
about
the
fact
that
you
need
padding
for
the
data
and
closed
in
in
a
variant
since
we're
doesn't
need
it
in
any
padding.
So
the
the
wording
in
this
back
wasn't
so
clear.
A
So
it
sounded
like
you
don't
need
any.
You
don't
had
the
some
thing
that
is
inside
the
variant
either
so
I
was
like
yeah
makes
sense,
so
I
went
with
this
Impa
sumption,
but
just
needed
a
complete
change
of
the
whole
API.
So
went
back
into
it,
but
each
solution-
I
came
up
with
when
I
was
implementing
it
lifetimes,
made
it
very
hard
to
implement
it,
because
I
had
to
satisfy
all
the
lifetimes
and
change
it
in
my
stuff.
So
I
was
like,
let's
first
kill
all
the
lifetimes.
A
This
is
this
is
ridiculous,
so
I
came
up
with
a
solution
like
an
immutable
slice
of
data.
For
those
of
you
who
don't
know
the
rest
yet
so
RC
is
a
reference
counter
data
type
and
you
can
put
anything
in
it
and
that's
reference
counted,
so
you
don't
need
to
copy
it
around.
If
you
want
to
share
something
across
your
codebase,
you
put
it
in
RC
and
you
cloned
the
RC,
which
is
the
just
a
container,
but
the
actual
data
does
not
get
copied
or
cloned.
A
So
it's
very
efficient
way
of
you
know,
but
still
is
not
as
efficient
as
not
having
to
even
clone
the
RC,
of
course,
but
can
live
with
it
in
the
beginning,
so
yeah
it
was
a
way
of
slicing
a
data
and
each
part
of
the
code
having
its
own
slice
and
yeah.
So
it
worked
actually
and
I
got
rid
of
all
the
lifetimes.
It's
so
good.
A
A
A
A
That's
that's
how
you
do
it
and
then
there's
like
if
you
want
to
add
something
to
a
variant
you
create
that
data,
and
then
you
say
to
variant
and
then
you
encode,
the
variant
like
you
did
the
string
and
then
record
it
the
same
way
for
complex
types.
We
are.
We
asked
for
the
signature
when
decoding
because
we
don't
know.
A
But
I
don't
want
you
to
use
it
yet
so
back
to
efficiency.
Right
I
want
you
to
use
it
when
it's
efficient,
but
you
can
use
it
yeah.
If
you
don't
mind
having
to
change
your
code
later
and
if
you
really
need
is
for
some
reason,
I,
don't
know
why
you
would
eat
it
so
so
badly
that
you
can't
wait
for
another
month
or
two,
so
I
wanted
to
make
it
efficient
and
I.
A
Don't
think
I
can
make
it
efficient
without
breaking
the
API,
but
I
looked
into
it,
but
no
I
I
have
to
do
that.
Yeah
and
guess
what
was
the
first
issue
that
was
filed
on
this
crate?
Why
don't
you
use
survey
so
in
the
beginning,
I
thought
of
that.
But
I
looked
at
survey
and
I
had
like
cognitive
overload
right,
because
I
was
looking
into
how
Debus
works.
A
I
didn't
know
anything
about
the
internals
I
didn't
know
how
G
variant
works
on
that,
so
that
was
enough
load
on
my
head
already
and
I
was
super
distracted
by
this
thing
called
work.
So
I
was
doing
this
in
my
spare
time,
so
that
was
enough
so
and
understanding
Sarah
is
not
trivial
either.
If
you
know
so,
yeah
I
am
now
that
I
have
something
that
that
proves
that
I
know
what
how
Debus
works
and
how
the
format
works
and
how
G
variant
works.
A
I
can
look
into
Sara
and
I
have
an
experimental
branch
where
I
have
have
a
basic,
like
you
know,
proof
of
concept,
serialization,
serializer
implementation,
it
looks
really
cool,
but
it's
just
a
proof
of
concept.
I
need
to
really
make
it
well
and
working,
but
the
main
challenge
with
Sarah
is
like
it's
too
generic.
A
So
you
get
a
data
it.
The
only
thing
that
it
will
implement
is
serialized
trait
of
sale
day
and
that
I
could
implement
that
for
specific
data
type
you
know
manually,
but
that's
also
very
generic,
the
serialized
implementation,
you
don't
you
can't
assume
anything
about
the
serializer
like
if
you
have
a
specific
serialize
err,
you
can't
assume
any
details
about
that
API.
It
has
to
be
serialized
abstract
to
serializer
and
the
other
way
around
to
and
see.
A
You
would
give
you
some
API
like
this
to
create
to
serialize
data,
so
I
say
two
bytes
and
you
I
get
a
vector
of
bytes
and
I,
give
it
a
value
that
implements
serialize,
but,
in
my
case,
I,
have
to
ask
you
for
one
more
trade,
which
is
variant
value,
but
it's
a
really
really
simple
trade.
All
it
has
is
one
method
required.
That
is
signature.
Do
you
just
give
me
your
signature
and
all
is
good
and
to
make
it
better,
I
will
provide
a
derive.
A
crow
like
Zelda,
provides
for
serialize
and
deserialize.
A
A
A
You
want
only
some
specific
data
from
from
that
array,
so
you
don't
want
to
read
the
whole
area
into
your
memory
and
read
it
all
and
know
yeah
so
I
would
hopefully
provide
a
you
know,
API
to
make
it
easy
and
an
efficient
at
the
same
time,
not
just
easy.
I
know,
of
course,
once
I'm
done
with
the
zero
and
business
I
can
do
the
thing
that
actually
meant
to
do
with
the
zebras
and
then
I
can
do
the
actual
thing
that
I
want
to
deceive
us
all.
B
A
Hope
so,
but
the
thing
is,
the
history
is
not
in
rust,
but
the
but
West
are
pmos
tree
or
what
is
it
called?
Ost
rpm,
something
like
that
that
one
is
in
most
of
it
is
in
in
rust,
so
I'm
hoping
that
at
least
they
will
use
this
API
and
I
have
been
told
by
other
people
who
are
using
variants
for
small
projects
here
and
there
they
said
yeah.
We
need
this.
A
Know
that
did
so
the
test
case,
the
test
case,
I
added
at
the
end
that
that
was
failing
was
the
for
the
dictionary
type
and
in
in
this
format
the
dictionary
type
is
an
array
of
dictionary
entry
types.
So
it's
like
a
struct,
you
know,
and
this
for
structure
the
encoding
is.
The
alignment
is
a
byte.
So
before
that
all
my
test
cases,
they
didn't
have
eight
bytes.
So
as
soon
as
I
had
it
by
element
in
in
my
test
case,
in
an
array
there
was
yeah,
it
started
filling
so
yeah.
D
A
A
So
if
you,
if
you
go
and
look
at
that,
talk,
and
also
there
is
some
documentation,
if
you
google,
for
rust
variance-covariance,
you
will
find
these
I
think
it's
more
like
internal
Docs
or
something
that
also
helps
a
lot,
but
other
than
that
there
is
the
rust
book
the
from
O'reilly.
It
does
also
a
pretty
good
job,
at
least
for
intro.
That
is
a
very,
very
good
job,
but
the
rest
is
just
you
know.
A
E
The
one
thing
about
lifetimes,
I
kind
of
realize
previously
it's
more
related
to
the
fact
that
a
lot
of
super
useful
traits
that
make
working
with
Russ
very
convenient
like
Darrell,
for
example,
they
actually
circumvent
the
issue
of
lifetime's
by
working
with
zero
size
types.
So,
for
example,
if
you
have
a
path
buff,
which
is,
you
know
again,
and
an
object
which
owns
a
buffer
which
owns
which
owns
a
path,
and
you
have
the
path
type
and
you
want
to
what
have
you
reference
the
path
buff
to
go
to
the
path?
E
Yeah,
the
same
for
string
two
and
back
to
you
know
slice.
When
you
go
into
the
code,
you
actually
realize
that
what
you
return
is
a
different
type
which,
however,
is
not
created
within
the
function
that
you
know
returns
it,
and
that
only
works
because
of
some
like
trickery
inside
the
compiler.
Now
I'm
saying
this,
because
I
was
always
trying
to
do
something
like
what
you
did
so
you
created
a
type
which
is
generic
over
a
lifetime
a
and
then
this
holds
a
reference.
Something
else.
Yeah.