I have the following two structs with const generics:
struct IntPrinter<const I: usize> {}
impl<const I: usize> IntPrinter<{ I }> {
fn print() {
println!("{}", I);
}
}
struct FollowingIntPrinter<const I: usize>
{}
impl<const I: usize> FollowingIntPrinter<{ I }>
where [(); { I + 1 }]:
{
fn print() {
IntPrinter::<{ I + 1 }>::print();
}
}
Calling FollowingIntPrinter::<41>::print();
prints the number 42
as expected.
The problem is that, when I change the type from usize
to u8
, it doesn't compile anymore. Instead, it complains that usize
was expected but u8
was found. Is there any way to fix this?
In my real project, I'd like to use an enum with two values as a type. The caller would specify one value as a const value, and internally, I'd have a second one with the other value. I guess this is too much to ask...?