I need to do something like
#[cfg(target_pointer_width = "64")]
pub type PlatformWord = u64;
#[cfg(not(target_pointer_width = "64"))]
pub type PlatformWord = u32;
because I need a uXX type identical in size to usize. usize does not participate to Into/From conversions except for trivial cases, and I need to write trait bound like usize: Into<u32>.
The (debatable) logic is that target_pointer_width is a "natural" type for the architecture.
Possibilities are: PlatformWord, TargetWord, ArchWord, HostWord, but I'm leaning recently towards Usize.
I'm sure someone else had the same problem, so I'd love to hear suggestions and comments. This is just cosmetic, of course.
EDIT: I forgot to say that in the intended usage, values of type PlatformWord are basically never indices. So in an ideal world there would be a best integer type for a platform, with size possibly different from usize, and I'd use that.
NativeWord is another contender.
UPDATE: I found another motivation, that has nothing to do with the “best word“ angle that caused so much controversy.
In sux, we methodically delegate through structures all traits that can be delegated. If you put a rank structure around a bit vector, you'll still get all the bit vector read-only access by delegation, beside the ranking methods. The traits are many, and delegations (courtesy of ambassador) are complicated.
Some structures work both for u32 and u64, and so they get twice the delegations. In some cases, I'd like to use for these structure usize because it scales with the platform, and in those cases it's reasonable because the structures are related to indexing (e.g., the selection structure on an Elias–Fano representation), and usize is for indices.
If I don't have NativeWord, I get thrice the delegations because I have to delegate for usize, too. That's a very good reason to have a type alias like the one I'm asking for.
Yes, you can cfg your default choice into the structure, but then every crate using it has to cfg their usage of the structure if they ever have to write an explicit type, which is a nightmare.