I want to be able to ensure at compile time that the functions that implement a trait get an array with the correct length.
The following is the straightforward way i wanted to implement it.
But because &[i32] != &[i32; 1] it doesn't work.
Is there solution for this problem?
trait Test{
fn test(arr: &[i32]) -> i32;
}
struct I{
}
struct J{
}
impl Test for I{
fn test(arr: &[i32;1]) -> i32 {
arr[0]
}
}
impl Test for J{
fn test(arr: &[i32;2]) -> i32 {
arr[1]
}
}
fn main() {
let arr = [1];
let a = I::test(&arr);
let b = 1;
assert_eq!(a,b);
}