I want to call a function if a condition is met and return multiple values that will be used outside the scope of the conditional block. If the function were only to return one value I would declare the variable at an appropriate earlier point, but as far as I can tell Rust does not allow for assignment of multiple variables unless these variables are also being declared.
Is there a way around this?
Here's some pseudo-code to illustrate my question:
// This approach doesn't work for scope reasons
fn function(inp1, inp2) {
calculate results;
(var_a, var_b, var_c)
}
fn main() {
let state = true;
if state == true {
let (var_a, var_b, var_c) = function(input_1, input_2);
}
do something with var_a, var_b, and var_c;
}
// This approach works when returning one variable
fn function(inp1, inp2) {
calculate results;
var_a
}
fn main() {
let var_a;
let state = true;
if state == true {
var_a = function(input_1, input_2);
}
do something with var_a;
}