I'm providing a default value for a const generic type but the Rust compiler tells me it "cannot infer the value of const parameter". It seems to ignore the default. Am I using this feature wrong? Is this how it is supposed to work? Then why use defaults at all? I use nightly 1.60.
const DEFAULT_N: usize = 73;
struct Foo<const N: usize = DEFAULT_N>;
impl<const N: usize> Foo<N> {
fn new() -> Self {
println!("N is: {}", N);
Self
}
}
fn main() {
Foo::new();
}
impldeclaration ?implblock is an error. (error: defaults for const parameters are only allowed in struct, enum, type, or trait definitions)