And a compile error shows up over the pattern_type! declaration: "Unconstrained generic constant". I don't understand why I can't use the declared generic constant in pattern_type!'s bounds. I think this should be totally valid.
I know that currently pattern_type! is an experimental and internal feature, so is this error a result of the incompleteness of this feature?
Based on reading the tracking issue for generic_pattern_types, I'd say this feature is quite early-stage and that most things are still very much unimplemented (there is not even a RFC yet). The pattern type as the return type of a function works, for example:
Thanks for the explanation! Currently I am trying to use this pattern_type! for niche optimization. If this is not currently possible I'll use the regular data type and leave this optimization for a future version of Rust.
error: generic parameters in const blocks are not allowed; use a named `const` item instead
--> src/lib.rs:13:61
|
13 | pub struct OTone<const EDO: u8 = 12>(pattern_type!(u8 is 0..EDO));
| ^^^
|
= help: consider factoring the expression into a `type const` item and use it as the const argument instead
While I would love to start fixing things here, we don't have an overarching plan for it yet, so are hesitant to do small patches for now.
That said, if you're willing to jump through some hoops, you can use ..= which has fewer restrictions (it doesn't need to do const eval to do ED0-1), and should work for more cases. You'll probably run into other restrictions if you do something complex, especially around trait impls