I want to index elements in my datastructure starting from 0 using
usize. But, I also would like to be able to store a lot of
Option<usize> without wasting space, i.e. I would like the
Option to have zero space overhead.
I know that there is NonZeroUsize in the standard library. But since I want to start from 0, that does not really work for me. Instead I would like to use the maximum value of
None value. Is there a crate/type for something like this?
I know that there is the
optional crate, which has the disadvantage that its
Optioned type is different from the stdlib
Option type. I would be nice to replace the type inside the
Option, and not the
rustc_layout_scalar_valid_range_end doesn't seem to work.
#[rustc_layout_scalar_valid_range_end(18446744073709551614)] pub struct LimitedRange(usize);
error[E0658]: the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable niche optimizations in libcore and will never be stable --> traitgraph/src/index.rs:13:1 | 13 | #[rustc_layout_scalar_valid_range_end(18446744073709551614)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^