3 ms·
I know, but it's "std::ptr::null", not "std::ptr::nil", which was the point of this discussion. (Clearly it has a concept of null pointers, even if they're used
by lobster_johnson 10y ago
I know, but it's "std::ptr::null", not "std::ptr::nil", which was the point of this discussion. (Clearly it has a concept of null pointers, even if they're used in a more limited manner than other languages.)
- kibwen 10y agoBut you can't use `std::ptr::null()` in the same way that you use null in the other languages mentioned there. It's literally just there for C interop, and it's called that because that's the terminology that C uses. For finding an analogue for the typical null use case in Rust, one would use the `None` variant of the `Option` enum.
- yberreby 10y agoNitpick: `std::ptr::null()` is not just there for C interop. It's also useful when writing pure Rust unsafe code.
- Gankro 10y agoCan confirm, used null all the time in Rust. The raw pointers are important native Rust constructs, although they do skew to supporting C idioms as much as possible (e.g. `* const T` and `* mut T` is basically a worthless distinction within Rust itself).
- sdegutis 10y agoSo in other words, std::ptr::null is Rust's version of null for situations where you would actually use null in C, except in general Rust discourages trying to use it like it's C. Seems reasonable.