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

Alice Ryhl

๐Ÿ‘ค Speaker
505 total appearances

Appearances Over Time

Podcast Appearances

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

But if you have your struct and you're passing it over functions, it might not be possible to make that analysis.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

And so you just get a compiler error.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

And so in this case, the solution is maybe to use a different pointer type.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

For example, the reference counter pointer type often solves this kind of bug.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

So the solution is, again, to change the data structure.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

So let me begin with the what, and let's take the why afterwards.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

So the what is, so unsafe is the escape hatch, essentially.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

So I explained before how there are certain bugs where if your program has one of those bugs, that's usually a security vulnerability.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

What Rust ensures is that if you have no use of unsafe,

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

then no matter how stupid your code is, you will never have one of those bugs.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

Now, if you do use unsafe, then there are still some guarantees, but it's a bit weaker.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

Because each unsafe operation that you can perform has a list of rules,

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

And if you violate these rules, then you might end up with one of these bad bugs.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

But of course, if you don't, then it's okay.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

And it's interesting to point out here that Unsafe does not disable the borrow checker or anything like that.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

It just gives you a few more operations you can perform that are not safe in general.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

And so you have to check yourself, yeah, this is actually okay in this particular case to, I mean, let's take the vector example again.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

Normally when you index index five, it will say, oh, let me check the length.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

So if the length is at least six, then it's okay.

The Pragmatic Engineer
Why Rust is different, with Alice Ryhl

Otherwise you get a crash.