Below code worked fine with me:
fn get_weights(gdp_sale: Vec<Model>) -> (f64, f64) {
let mut constant = 1f64;
let mut slope = 1f64;
let accepted_diff = 0.01f64;
loop{
let (new_constant, new_slope) = step_cost_function_for(&gdp_sale, constant, slope);
if (constant - new_constant).abs() <= accepted_diff
&& (slope - new_slope).abs() <= accepted_diff
{
return (new_constant, new_slope) // problem happen if the `return` removed
}
else {
constant = new_constant;
slope = new_slope;
println!("new values for constant and slope are {}, {}", new_constant, new_slope);
}
}
}
But if I removed the return
word, I get the below error:
error[E0308]: mismatched types
--> src/main.rs:75:13
|
75 | (new_constant, new_slope)
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found tuple
|
= note: expected type `()`
found type `(f64, f64)`
error: aborting due to previous error