paholg / typenum

Compile time numbers in Rust.
https://crates.io/crates/typenum
Other
518 stars 46 forks source link

const generics integration #163

Closed tarcieri closed 2 years ago

tarcieri commented 3 years ago

Perhaps this is already possible today, but I'd be curious to know (and I assume others would too):

If we have code that leverages typenum today which we would like to slowly transition to const generics (particularly across crate boundaries), is there a way to do so?

That is to say, is it possible to go from typenum types like U0, U1, etc to const generic parameters? Do the existing methods defined on traits like Unsigned make this possible?

paholg commented 3 years ago

Both Unsigned and Integer traits have static methods and associated constants that give you "normal" numbers. I haven't played with const generics in a while, so I'm not sure if they work for that yet, but that would be the way.

https://docs.rs/typenum/1.12.0/typenum/marker_traits/trait.Unsigned.html

Example:

use typenum::{Unsigned, U27};

const num: u64 = U27::U64;
tarcieri commented 3 years ago

Seems like what I had in mind isn't possible with min_const_generics, unfortunately

Screen Shot 2021-03-05 at 7 46 23 AM