Is your feature request related to a problem? Please describe.
Currently, const only accepts primitive types. When defining color constants for a graphics library, I cannot use const:
struct Color {
r : Int
g : Int
b : Int
a : Double
}
const RED : Color = { r: 255, g: 0, b: 0, a: 1.0 }
// ❌ Error: Color is not a valid constant type, only immutable primitive types are allowed.
Describe the solution you'd like
Allow const with struct types when all fields are constant expressions:
const RED : Color = { r: 255, g: 0, b: 0, a: 1.0 } // Would like this to work
Describe alternatives you've considered
Using pub let works as a workaround:
pub let red : Color = { r: 255, g: 0, b: 0, a: 1.0 }
Additional context
- Environment: moon 0.1.20251227 (nightly, feature: rupes_recta)
- I'm imagining something similar to Rust's const structs:
// rust
struct Color { r: u8, g: u8, b: u8, a: u8 }
const BLACK: Color = Color { r: 0, g: 0, b: 0, a: 255 };
fn main() {
println!("Black: ({}, {}, {}, {})", BLACK.r, BLACK.g, BLACK.b, BLACK.a);
}
Is your feature request related to a problem? Please describe.
Currently,
constonly accepts primitive types. When defining color constants for a graphics library, I cannot useconst:Describe the solution you'd like
Allow const with struct types when all fields are constant expressions:
Describe alternatives you've considered
Using pub let works as a workaround:
Additional context