2 ms·
Yes, but in Rust there are two independent axes here: - Whether or not a library calls unsafe code internally - Whether or not a library declares its public A
by brundolf 6y ago
Yes, but in Rust there are two independent axes here:
- Whether or not a library calls unsafe code internally
- Whether or not a library declares its public API to be unsafe (https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#calling-an-unsafe-function-or-method https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#call...)
It's very much possible (essential, even) to be able to present a safe API to external callers of your code, despite using unsafe code under the hood. In this case you're making a human-checked assertion of safety, which is not guaranteed to be without bugs, but the important thing is that you're minimizing the surface area of un-safety and declaring a contract with your users. You're "stopping the buck" of unsafety rather than passing it on. The parts that really have to be unsafe can enjoy extra scrutiny, and everything else (including the caller's code) can be checked by the compiler. This is not uncommon in the standard library and other low-level libraries.
More information here: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#creating-a-safe-abstraction-over-unsafe-code https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#crea...
- josephg 6y agoSure. So this library exposes all of Microsoft’s DLL surface area in an API-native way. That’s important. Now that it’s released, library authors can wrap this with another library, which abstracts over win32, reexposing it in safe rust. Wrapper libraries like that almost certainly won’t cover 100% of the api surface area - there are so many functions in the windows APIs. Anyway, give it time. People will wrap this with safe rust.
- brundolf 6y agoWhich is exactly what I suggested in my original comment :)