Re:Smoltcp: A small TCP/IP stack in Rust
by kibwen on Thursday June 20, 2019 @11:09AM
(#20233665)
Not within the unsafe blocks itself, no. A more pertinent metric might be "number of lines of code in any modules that contain the `unsafe` keyword". It's true that certain operations can only happen within the unsafe block itself, but those operations can potentially invalidate safety-critical invariants being upheld by any code that the unsafe block can reach, which means the buck ultimately stops at the module boundary. If you have a module that contains unsafe code, factor out the bits that need `unsafe` into as small a submodule as possible with a well-considered interface so that you have as little code to audit as necessary.
The fortunate thing is that, in practice, you can program in Rust for years without ever needing to write an `unsafe` keyword, depending on your chosen domain. `unsafe` is mostly useful for calling external C code, for implementing maximally-efficient custom data structures, and interfacing with hardware.
The fortunate thing is that, in practice, you can program in Rust for years without ever needing to write an `unsafe` keyword, depending on your chosen domain. `unsafe` is mostly useful for calling external C code, for implementing maximally-efficient custom data structures, and interfacing with hardware.