tkaitchuck / constrandom

Macro to generate random constants in Rust https://xkcd.com/221/
Apache License 2.0
73 stars 14 forks source link

Usize support #14

Closed dtolnay closed 4 years ago

dtolnay commented 4 years ago

const_random!(usize) and const_random!(isize) are not currently supported. This is likely because the proc macro runs on the host and may have a different usize size than the target.

One approach that would work for implementing these is to expand to an as cast:

const_random!(usize)

// expands to:
const_random!(u128) as usize

which will truncate high bits and produce a correctly usize-sized random value.

tkaitchuck commented 4 years ago

Done https://github.com/tkaitchuck/constrandom/commit/d6982324dec0181bad039e9bdd0955544b2330ad