I am getting mismatched types error, expected u16, found () from this function (code below) and I can’t seem to find why because it is guaranteed to return u16 or am I missing something?
assign_value is a method of my struct and type self.fields is Vec<Vec<u16>>.
pub fn assign_value(&self, input: u16) -> u16 {
for (row, vector) in self.fields.iter().enumerate() {
for (collumn, value) in self.fields[row].iter().enumerate() {
if *value == 0 {
return input;
}else {
return *value;
}
}
}
}
>Solution :
What if self.fields is empty? In this case, the loop won’t be executed at all. What will be returned?
In general, all loop kinds except loop without break cannot affect whether the function will return, because they can not run.