Alice Ryhl
๐ค SpeakerAppearances Over Time
Podcast Appearances
But if you have your struct and you're passing it over functions, it might not be possible to make that analysis.
And so you just get a compiler error.
And so in this case, the solution is maybe to use a different pointer type.
For example, the reference counter pointer type often solves this kind of bug.
So the solution is, again, to change the data structure.
So let me begin with the what, and let's take the why afterwards.
So the what is, so unsafe is the escape hatch, essentially.
So I explained before how there are certain bugs where if your program has one of those bugs, that's usually a security vulnerability.
What Rust ensures is that if you have no use of unsafe,
then no matter how stupid your code is, you will never have one of those bugs.
Now, if you do use unsafe, then there are still some guarantees, but it's a bit weaker.
Because each unsafe operation that you can perform has a list of rules,
And if you violate these rules, then you might end up with one of these bad bugs.
But of course, if you don't, then it's okay.
And it's interesting to point out here that Unsafe does not disable the borrow checker or anything like that.
It just gives you a few more operations you can perform that are not safe in general.
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.
Normally when you index index five, it will say, oh, let me check the length.
So if the length is at least six, then it's okay.
Otherwise you get a crash.