"Hey, does anyone know an elegant..." <- there's a couple ways to achieve what you're trying to do. you can define the `const` variables in a file, like you mentioned. this is a lot of somewhat tedious work to do manually. you can generate the file at build-time using `build.rs` to generate the code in a file. basically, move the code from above into `build.rs`, and print out the `const` definition to a file in the `src` dir (a.k.a. meta-programming). if you are comfortable with procedural and/or derive macros, you could write a macro to help you define the `const` for you. hope that helps