2 ms·
This is specious reasoning. You have to go out of your way to write unsafe broken code. The default in Rust is for memory safety. Yes, someone could theoretical
by eridius 10y ago
This is specious reasoning. You have to go out of your way to write unsafe broken code. The default in Rust is for memory safety. Yes, someone could theoretically be using an unsafe block and raw pointers to manipulate a memory buffer. But they probably aren't, because that's generally pretty stupid unless you're implementing a higher-level wrapper around the buffer, which very few people do because there's generally already a wrapper that does what you want (often provided by the stdlib). And even if you are, the unsafe code is contained in a very small area which makes it much easier to review for safety.
- simion314 10y agoI was talking about the low level code like in this case where you interact with the kernel, for calling kernel/OS functions you will have to pass pointers and buffers around,I am not sure if you can wrap the kernel functions without making things slower by adding indirection.
- eridius 10y agoFor any call that takes a raw pointer and a length, you can create a trivial wrapper that takes a &[u8] or &mut [u8] instead in order to make it safe. And you probably should do that, because you don't want to be sprinkling `unsafe` throughout your entire codebase. If you're really worried about indirection, you can also mark these inline, but they're small enough that the compiler would probably inline them anyway.