Menu
Sign In Search Podcasts Charts People & Topics Add Podcast API Blog Pricing

Sebastian Scholz

๐Ÿ‘ค Speaker
485 total appearances

Appearances Over Time

Podcast Appearances

Rust in Production
Gama Space with Sebastian Scholz

But those are safer conversions than just using transmute.

Rust in Production
Gama Space with Sebastian Scholz

And the fact that the type system guarantees no just random conversion between different types is really helpful to reason about these invariants in your code.

Rust in Production
Gama Space with Sebastian Scholz

So, for example, just think about in C, I can create any struct at any point in any time.

Rust in Production
Gama Space with Sebastian Scholz

In Rust, you need unsafe to do that.

Rust in Production
Gama Space with Sebastian Scholz

And it's a big kind of flag.

Rust in Production
Gama Space with Sebastian Scholz

If you see unsafe in the code, it helps you during the review because when you use unsafe, you always need to prove, at least with a comment, that certain invariants are holding up.

Rust in Production
Gama Space with Sebastian Scholz

And that makes it very easy to prove that your code can be safe, even if you're using unsafe.

Rust in Production
Gama Space with Sebastian Scholz

So unfortunately, we still have C libraries underneath, which are all unsafe.

Rust in Production
Gama Space with Sebastian Scholz

I mean, it's C code, so there's no help from the Rust compiler there.

Rust in Production
Gama Space with Sebastian Scholz

And so interfacing with those does require unsafe boundaries, unsafe blocks.

Rust in Production
Gama Space with Sebastian Scholz

But when we write our wrapper functions for these functions in the C libraries, we make sure that all of the unsafe free conditions that need to be met for this library to be called are met.

Rust in Production
Gama Space with Sebastian Scholz

And one of the examples is, as I said, the CSP library, where we make sure that it's initialized before we use any of the functions.

Rust in Production
Gama Space with Sebastian Scholz

Yeah, so direct unwraps are also somewhat forbidden in our code.

Rust in Production
Gama Space with Sebastian Scholz

The best that we can do are expects, where you provide a message and a reasoning of why this certain thing can never fail.

Rust in Production
Gama Space with Sebastian Scholz

And there's still a few pain points in Rust with this, where you do need to unwrap certain things.

Rust in Production
Gama Space with Sebastian Scholz

For example, think about creating a non-zero value.

Rust in Production
Gama Space with Sebastian Scholz

You can do this unwrapping or this expecting in const code, which is very nice.

Rust in Production
Gama Space with Sebastian Scholz

So you can make it a compile time error.

Rust in Production
Gama Space with Sebastian Scholz

Yet still, it's unfortunate that certain things can't be expressed correctly

Rust in Production
Gama Space with Sebastian Scholz

as you want them and need to be unwrapped.