I think you'd run into a couple problems...
- The
std::ops::Index
trait expects you to return a reference and not a value, so you'd need to either rely on[T; FIBS.len() - 1]
beingCopy
or use something else - You need to move the runtime value,
1..
(aRange<usize>
) to something compile time - We need to use
unsafe
and pointer arithmetic in aconst fn
- Const generics need to be able to express conditions like
N < M
in a where clause
Here's my take:
struct Array<T, const N: usize>([T; N]);
struct Range<const Start: usize>;
impl<T, const N: usize> Array<T, N> {
pub const fn slice<const Start: usize>(self, range: Range<Start>) -> [T; N - Start]
where
Start <= N,
{
unimplemented!("Magic...")
}
}