I wrote this code to see what happens when I pass two strings to a function and return them back again:
fn main() {
let mut s3 = String::from("hello");
let mut s4 = String::from("wolrd");
(s3, s4) = take_n_giveback(s3, s4);
println!("{0} and {1}", s3, s4);
}
fn take_n_giveback(x: String, y: String) -> (String, String) {
(x, y)
}
I am getting an error which is not helpful:
error[E0070]: invalid left-hand side expression
--> src/main.rs:5:5
|
5 | (s3, s4) = take_n_giveback(s3, s4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ left-hand of expression not valid
This operation works fine when passing single string and returning back.
fn main() {
let mut s3 = String::from("hello");
s3 = take_n_giveback(s3);
println!("{0} ", s3);
}
fn take_n_giveback(x: String) -> (String) {
x
}
What's wrong here? What is the meaning of the error and in what situations can be encountered in code?