Hello everyone. I'm currently exploring generic types from the documentation. I have a question regarding the code. I wrote two functions, after the loop you can see the largest. Why write this, what does it do?
fn largest_i32(list: &[i32]) -> i32 {
let mut largest = list[0];
for &item in list {
if item > largest {
largest = item;
}
}
largest // why is it?
}
fn largest_char(list: &[char]) -> char {
let mut largest = list[0];
for &item in list {
if item > largest {
largest = item;
}
}
largest // why is it?
}