4 ms·
Ahh, I stand corrected. It is possible to implement an intrusive collection without making the caller use unsafe. For some uses. For the others he's abstract
by rstuart4133 1y ago
Ahh, I stand corrected. It is possible to implement an intrusive collection without making the caller use unsafe. For some uses.
For the others he's abstracted the unsafe calls to just cursor_from_ptr and cursor_mut_from_ptr. I suspect they would see heavy use, but he's reduced the safety guarantees you have to prove to the absolute minimum. Colour me impressed. I wish I had thought of that.
I might become the 5,243,766 + 1 user.
As for this:
> Using one when you don't need to would be considered bad, but unsafe exists to be used when necessary. Nobody shuns unsafe code purely for it being unsafe code.
Hmmm. You've just contradicted yourself. You've just said if you were given a safe and unsafe implementation of the same thing, you would shun the unsafe version. Than go on to say "Nobody shuns unsafe code purely for it being unsafe code".
But if you want a another example, try: https://news.ycombinator.com/item?id=45516255 https://news.ycombinator.com/item?id=45516255. Two of his three reasons are easily solved with unsafe.
- steveklabnik 1y ago> You've just contradicted yourself. No, I did not. It is true that nobody shuns unsafe code for simply being unsafe. Choosing a safe alternative over an unsafe one means that there is an alternative. Unsafe code to do the job that unsafe code is meant to do is totally fine. That’s the reason it exists!