Building a Safe, Idiomatic Rust Wrapper Around C

SpatialOS:

Some Background

A networking layer for multiplayer games:

  • Persistence
  • Scale
  • Simulation

Provide direct support for popular game engines:

  • Unity
  • Unreal Engine 4

Supports multiple languages:

  • C++
  • C#
  • Java
  • C
  • RUST??????

The Connection Object and Thread Safety

Is it Send?

Is it Sync?

To the forums!

... or wrapping it in a mutex.

It's safe to access from different threads, so long as only one thread accesses it at a time.

It doesn't use global variables

There's no shared state, methods mutate data within the struct in an unsynchronized way.

Speaking of OpList...

Playing With Pointers

How do we differentiate between owned and borrowed data?

What if we LIED?

  • The data is completely opaque
  • We never dereference the pointer
  • All we care about is the value of the pointer
  • Sometimes we own the data
  • Sometimes can mutate the data
  • Sometimes we can only read the data

Rust has conventions for this:

  • Box<T>
  • &mut T
  • &T

One more thing...

The End