Rust and Unsafe

69 points fluffysoftdev

I read a lot about Rust's unsafe features being a struggle and ultra confusing. This just hasn't been my experience with unsafe Rust.

I decided to make an allocator which obviously uses raw pointers for faster initialisation times. I managed to get what takes the standard library 22s to initialise, done in 600ns which my implementation.

Although, the ownership semantics aren't active when using raw pointers, and that they must be accessed and obtained with methods like add and offset. It just doesn't feel like unsafe Rust is really difficult.

The unsafe keyword makes it explicit and easy to keep the parts which need that extra care easy to spot and it makes you focus on that section.

Maybe it is because I'm used to C++ but I actually really like the way Rust does this and now i have the ability to speed up some of my allocations. Has anyone else had a good experience with unsafe Rust?