let a: [u16; 3];
let ord: u8 = a.len().try_into().unwrap() - 1;
The try_into() part is giving this error message that looks cryptic:
type annotations needed
cannot infer type for type parameter U
note: cannot satisfy _: std::convert::TryFrom<usize>
note: required because of the requirements on the impl of std::convert::TryInto<_> for usizerustc(E0283)
test.rs(51, 19): this method call resolves to std::result::Result<T, <Self as std::convert::TryInto<T>>::Error>
test.rs(51, 27): cannot infer type for type parameter U
Could you please tell me what does it want from me?
The compiler is not able to figure out what type the length should be converted into. All it knows is that it's a type you can subtract some integer from and get an u8, but since there could be many such types, this is not fully constrained. For example, you could even define your own custom type and implement both TryInto<YourType> for usize and YourType - i32 with output type u8. This would fit the constraints.