You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking issue for migrating from GenericArray to const generics #970
We've had an informal plan to migrate from the generic-array/typenum crates for years. People ask about it quite frequently ever since min_const_generics have been stabilized. I thought it would be good to have a tracking issue we can point people to.
Unfortunately min_const_generics is not quite up to the challenge of replacing our existing usages of generic-array. Here are open issues tracking the two main features we need upstream:
The first issue (60551) is arguably the biggest blocker. All of the trait crates defined in this repo use associated ArrayLength types which would be best replaced by associated constants. While it would be possible to switch from associated constants to const generic parameters, this has all the drawbacks of using explicit generic parameters versus families of them expressed as associated types. It becomes quite unwieldy when there are several of them involved. Our use cases benefit from these constants being "carried along" with another generic parameter, so it would be best to wait until this feature is implemented.
The second issue (76560) is important because we do quite a bit of arithmetic with typenum.
It will probably be a year or two before these features are implemented upstream, at which point we can consider a wholesale migration to const generics.
Something I've been experimenting with is flex-array, a crate which is a hybrid of const generics and typenum-based arrays, which would make it possible to start using const generics in some capacities but still retain the full expressiveness of typenum along with the ability to define array sizes stored as associated types ala generic-array's ArrayLength:
I started by trying to modify generic-array then quickly noticed that the approach would be a lot more effective if such a crate were built on const generics from the ground up.
I think a crate like this could provide a useful stepping stone for incrementally migrating to const generics.
Reacted by Deirdre Connolly, sonder-joker and Jess
There's been some talk about potentially stabilizing associated constant support as the next step for const generic stabilization: rust-lang/rust#76560 (comment)
Reacted by Jeff Burdges, Elichai Turkel, Deirdre Connolly and Kevin K.
It can hopefully provide a stepping stone from where we're at now towards a full migration to const generics. Ideally this would include being able to use const generic core arrays in public-facing APIs.
Reacted by Alex Martens, kamulos, Zgarbul Andrey, Erik, Kamyar Mohajerani, Luis Enrique Muñoz Martín, Agustín Covarrubias, Agost Biro, François Garillot, Trevor Gross and 1 more
Activity
tarcieri commentedon Mar 27, 2022
Something I've been experimenting with is
flex-array, a crate which is a hybrid of const generics andtypenum-based arrays, which would make it possible to start using const generics in some capacities but still retain the full expressiveness oftypenumalong with the ability to define array sizes stored as associated types alageneric-array'sArrayLength:RustCrypto/utils#707
I started by trying to modify
generic-arraythen quickly noticed that the approach would be a lot more effective if such a crate were built on const generics from the ground up.I think a crate like this could provide a useful stepping stone for incrementally migrating to const generics.
tarcieri commentedon Apr 16, 2022
There's been some talk about potentially stabilizing associated constant support as the next step for const generic stabilization: rust-lang/rust#76560 (comment)
tarcieri commentedon May 12, 2022
I've published a crate named
hybrid-arraywhich aims to provide the same functionality asgeneric-array, but in a way that can be composed with const generics: https://github.com/RustCrypto/utils/tree/master/hybrid-arrayIt can hopefully provide a stepping stone from where we're at now towards a full migration to const generics. Ideally this would include being able to use const generic core arrays in public-facing APIs.
tarcieri commentedon Nov 14, 2023
We've migrated to
hybrid-arrayin most of the crates in this repo now, although the work still needs to be done to update the various implementations.tarcieri commentedon Jan 21, 2024
Closing this out in favor of #1481, now that the migration from
generic-arraytohybrid-arrayis largely complete