News for hackers. Stuff that matters.
Re:Overhead of Returning Optional Values in Java and Rust by ridiculous_fish on Saturday October 16, 2021 @01:55PM (#28889850)
This is the first I've seen `num::NonZeroU64` which is nice, intrusively using a zero value to mean none.

Is there any analog for a const pointer? I want to point into or just beyond a const array, intrusively using null as a None value.

There is `ptr::NonNull` but this always converts to a *mut T, and one is just supposed to "be careful" to not use the mutable features if your pointee isn't actually mutable.

Re:Overhead of Returning Optional Values in Java and Rust by returningfory2 on Saturday October 16, 2021 @03:02PM (#28890450)
Anything of type `&T` has the same sizing property as `num::NonZeroU64`: the size of `Option<&T>` is the same as the size of `&T`. So I think you would just use a plan old Option?
Re:Overhead of Returning Optional Values in Java and Rust by ridiculous_fish on Saturday October 16, 2021 @03:54PM (#28890901)
The problem with &T is that you can't make one to just-past-the-end of an array.

If you look at the implementation of slice::Iter, it stores a (cursor, end) pointer pair, but there's no way to say "this is a non-null const pointer" so it casts the cursor pointer to *mut.

https://doc.rust-lang.org/src/core/slice/iter.rs.html#67