Initial migration from const-generics to typenum
This is an initial PoC of what a migration to use of typenum and GenericArray might look like.
(Not the developer, just curious)
Could you expand on what the motivation for moving away from const generics is here?
typenum allows you to do things like specify legal values at compile time, as well as removes the need to choose an integer type until runtime.
For example, if you wanted to implement a "sub-matrix" extension trait, you could constrain it so its width and height is less than the matrix it's extending. when you are placing it in the "super-matrix", you can constrain it so that it's left most column, plus its width is less than the width of the super-matrix, and similarly for the highest row.
this is all at compile time.
as for integer types, you do not need to choose usize, u32, etc., until an actual machine-representation of the integer is required.
Thank you for the explanation!
Another way to put it:
const generics allow you to specify "use u32/usize/u64/etc here", typenum says "use any integer value here", and you can specify what "legal" is (non-zero, even/odd, the result of arithmetic, etc)
oh yeah, that's the other thing: you can do arithmetic with typenum. no need for SIZE because you can just derive that within the type system my multiplying the width-type by the height-type.
I've looked through the PR, afaict, typenum brings us the compile-time checking and calculation features, which could be very useful. But now I tend to not use it because:
- The last release of
typenumwas over 1 year ago, I'm not sure whether it's been actively maintained. - The compile-time checking part can be done in proc-macro, by checking values set in
keyboard.toml. We've already had some, like: https://github.com/HaoboGu/rmk/blob/6ea066a128b0f1d04c5ab383ba78a98137fa6556/rmk-macro/src/keyboard_config.rs#L372-L386 - The compile-time calculation part could be covered by https://github.com/rust-lang/rust/issues/76560.
typenumhas a long history, it appeared even beforeconst_generics. But for the future, I prefer to use features provided by official Rust, not a third-party crate.
After our discussion in DMs, I'd be happy to re-write the PR so that it only affects the internal code-base, and not the public facing API.
Closing this due to no activity. If you still want to work on it, please feel free to reopen it!