Hacker News new | past | comments | ask | show | jobs | submit login

Considering that unsafe rust basically just allows raw pointer access (see link below) which is already a thing you can do normally in C, I do not see how that's a very good argument against it honestly.

As for the Option type, it is exactly what it says. It's an optional, non-nullable node generic over type T. I suppose generics, optionals and the idea of non-nullable types might be exotic at first, but this is not a problem with Rust as much as it's a problem with C not being able to express these concepts in the first place and instead expecting you to spray null checks all over the place!

https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html




Not to be overly contrary here but, you "need to spray null checks" probably just as much in rust as in C (in this specific example, not in general). Since those prev/next pointers are being modified in unsafe code where either you're using NonNull::new() which contains the null check, or you're using NonNull::new_unchecked() which means you need to convince yourself all the invariants hold true. The situation is roughly equal in C (ie. once you prove in a module that fields cannot be NULL, no need to add lots of redundant extra NULL checks in all users of the module).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: