Module naga::non_max_u32

source ·
Expand description

NonMaxU32, a 32-bit type that can represent any value except u32::MAX.

Naga would like Option<Handle<T>> to be a 32-bit value, which means we need to exclude some index value for use in representing None. We could have Handle store a NonZeroU32, but zero is a very useful value for indexing. We could have a Handle store a value one greater than its index, but it turns out that it’s not uncommon to want to work with Handles’ indices, so that bias of 1 becomes more visible than one would like.

This module defines the type NonMaxU32, for which Option<NonMaxU32> is still a 32-bit value, but which is directly usable as a Handle index type. It still uses a bias of 1 under the hood, but that fact is isolated within the implementation.

Structs§