Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rust Const Generics

Presentation on Const Generics as of 1.50.0 stable and 1.52.0-nightly

Challenges

Learning

  • If your constant generic parameters are not integer/char/boolean, don't downgrade your domain.
    • Use #![feature(const_generics)] to allow structs and enums as const generic parameters.
    • Such struct/enums need #[derive(PartialEq, Eq)] (or their implementation).
    • Trust nightly.
  • Even though the purpose of (const) generics is to reuse code, the actual const generics code is repetitious. You'll have to repeat where clause in any impl that involves a type with const generic parameter, if the const generic parameter affects size of any field(s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment