I have a few methods in Rust that return two elements, and it really makes sense for me in those scenarios to return two elements. Though, when actually calling those methods I noticed that Rust does not allow using tuples as lvalue, so I cannot reassign to them. Assuming test()
is a method that returns two values, I end up writing a lot of code that looks like this:
let (mut val1, mut val2) = test();
for i in 0..100 {
// partially removed for brevity;
let (_val1, _val2) = test();
val1 = _val1;
val2 = _val2;
}
let (_val1, _val2) = test();
val1 = _val1;
val2 = _val2;
Usually the two values that are returned from my method are some structures, and in turn they have some methods too, so I want to call methods in those returned structs. Anyway, I use the above pattern a lot, and it becomes cumbersome very fast. Are there any better approaches to do what I want in Rust?