So say I'm writing a wrapper type for the array.
struct Array<const L: usize, T> {
raw: [T;L]
}
And I have some function that mutates the length of the array wrapper, say the function is concatenation:
impl<const L: usize, T> Array<L, T> {
fn concat<const L2: usize>(self, other: Array<L, T>) -> Array<{L + L2}, T> {todo!();}
}
When I try to compile this code, the rust compiler gets extremely mad. Thinking it might have something to do with adding types corresponding to implementing multiple, traits, i tried multiplication instead of addition, which also didn't work.
I know that rust can evaluate some expressions at compile time, is this just a case where that isn't allowed, or am I missing something?
You say that the compiler gets mad at you, but have you considered listening at what it was telling you?
Plugging your code into the playground, the first error is a trivial showstopper of
so it kind-of doesn't seem to because that's trivial to fix.
Now fixing that we get to the meat of the issue:
that seems to explain the entirety of the thing: what's currently enabled in Rust is the
MVP as in minimum viable products aka the smallest featureset which can be useful, and what that translates to is explained in the introductory blog post.
The first limitation is
which is fine here because you're using integral types, but the second limitation is
What is a complex generic expression? Anything outside of:
What you're trying to do does not work (outside of nightly with both
const_generics
andconst_evaluatable_checked
enabled) because you're writing constant expressions involving at least one generic parameter, which is not part of the MVP.