It does not work, because I need to sum into i64, and the trait Sum<&i32> is not implemented for i64.
I can do it explicitly: arr[start..=end].iter().map(|c| *c as i64).sum()
But, are there a way to write it with full type elision here? (Basically, I want to compiler to be smart enough to do it without manual type annotation/conversion based on function signature only).
The problem is that i64 implements both Sum<i64> and Sum<&i64>, so you have to pick one when converting from &i32. When faced with multiple possibilities, the compiler won't try to guess further, even though only Sum<i64> can ultimately work here.
You can at least avoid the possibility of truncating-as by writing .map(|c| i64::from(*c)). If you don't want a closure, you can make that .copied().map(i64::from).
Oh, by "truncating-as" I meant protecting from a mistake where the input type is larger than the output type. For example, if you refactored to arr: &[i128] for some reason, there would be no sign of trouble when you convert as i64 here, but it would be losing the upper bits of data.