Sebastian Scholz
๐ค SpeakerAppearances Over Time
Podcast Appearances
I mean, it's okay if you use the same pin for two different things.
You can write to the registers and it's not going to care.
But the end result is that
the pin is not going to do what you want because you're using it for two things at the same time.
And by expressing this notion of only one part of your program can use this specific thing via a token, the compiler can ensure that this, in fact, is the case.
Yes, we use this in a bunch of places.
Also, for example, for wrapping C libraries, it's kind of an interesting thing.
During our Gamma Alpha project, we used a communication protocol called CSP.
And unfortunately, at the time, there was no pure Rust implementation of it.
So we had no choice but to wrap, well, either implement the whole thing ourselves, but that would have taken quite a bit of time, which we didn't have, or to wrap the C library.
And the C library has a bunch of invariants when you use it.
One of them is you have to call a function called CSP init before you do anything else.
And so this kind of a thing, once again, we have a serial size struct in Rust called CSP.
It has an init function and it gives you, is the only place where you can get an instance of this CSP struct.
And then the CSP struct allows you to call other functions on itself.
But you need a self, so you need an instance of destruct.
And so that proves that you have initialized the CSP, the underlying C library.
There's only one place to get this token.
And in that place, we initialized the library just before.