I'm writing two versions of a trivial method to compute an average for an integer slice, and return an integer, and a second version that returns a float.

The first version, that returns an integer average, has this code:

```
fn compute_average(list: &[i32]) -> i32 {
{
let sum_of_items: i32 = list.iter().sum();
let count_of_items: i32 = i32::try_from(list.len()).unwrap();
let average = sum_of_items / count_of_items;
average
}
```

My question about the above:

a) why do some parts of Rust, like .len() return a usize while others, like sum() return an integer? It seems like if Rust wants to have a "soft size" that's platform dependent (like usize/isize) it should use it everywhere a count of length of something is returned.

b) is my try_from approach reasonable? I mean, is there a more direct way to do what I'm trying to do?

The float version has its own problems/questions:

```
fn compute_average(list: &[i32]) -> f64 {
let sum_of_items = f64::from(list.iter().sum());
let count_of_items = f64::try_from(i32::try_from(list.len()).unwrap()).unwrap();
let average = sum_of_items / count_of_items;
average
}
```

a) Initially I tried to f64::try_from(list.len()) but apparently that's not supported for usize (!?) but I did conclude that I could first convert the list.len() to i32 and then to f64, but that yields a pretty ugly piece of code - is there a better way to do this?

b) the first line "let sum_of_items" ... is erroring out that the compiler cannot infer the type T. I'm confused about this - what can't it infer, and how should I tell it what it wants to know? I tried casting "list.iter().sum()" as something like an i32, thinking that that would bring some clarity, but it didn't help either.

Thanks for any insights!

Always Learning.

Michael