Skip to content

Investigate min_generic_const_args for handling array sizes generically #180

Open

Description

@tarcieri

Currently we use macros to write a fixed set of supported sizes, which is inflexible and we would ideally support arbitrary sizes instead (#81). See:

https://github.com/RustCrypto/hybrid-array/blob/master/src/sizes.rs

It seems like min_const_generic_args could be the missing compiler feature we need to be able to use the associated constant typenum::Unsigned::USIZE as N for [T; N] when defining our Array type.

It would be good to try to make this work on nightly in a proof-of-concept capacity to ensure it will actually work for our use cases. It would also make a compelling use case for min_const_generic_args.

cc @BoxyUwU

Activity

  1. BoxyUwU commented on Apr 15, 2026

    @BoxyUwU

    i would be really interested in understanding your use case for more const generics related features, as well as specifically how mGCA may (or may not) fit into that. feel free to reach out on the rust-lang zulip or poke me here about anything, i'd be more than happy to try and understand what you've got going on :)

  2. tarcieri commented on May 2, 2026

    @tarcieri
    MemberAuthor

    Per Zulip it seems like this was prototyped successfully using the following definition of Array which becomes possible with with min_const_generic_args:

    pub struct Array<T, U: Unsigned>(pub [T; U::USIZE]);

    Hooray! Well there's one complication: it requires upstream changes to typenum to use the type const syntax in order for this to work. On the tracking issue for min_const_generic_args I see there's an unresolved question "Can we get rid of needing an annotation on const items for them being type consts?" so if that goes away this will be much easier.

    I suppose another thing to consider is min_const_generic_args largely eliminates the impetus for hybrid-array in the first place, where our main usage of hybrid-array and typenum is simply providing associated "constants" (i.e. typenum type-level unsigned integers) that are used to size arrays, and if we have that as a first-class feature in the language in cases where we don't depend on typenum type-level arithmetic expressed as bounds we can simply migrate to core arrays.

    For cases where we currently do depend on such arithmetic or other typenum predicates, I know @andrewwhitehead has been working on defining traits in terms of const generics without use of typenum which provide some of that functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions