Hello, is there a way to avoid using ref
while having that same functionality?
fn works(&(num, ref string): &(i32, String)) {
todo!()
}
Here num
would be i32
, but string
would be &String
.
Hello, is there a way to avoid using ref
while having that same functionality?
fn works(&(num, ref string): &(i32, String)) {
todo!()
}
Here num
would be i32
, but string
would be &String
.
You can make the bindings outside the parameters:
fn works(tuple: &(i32, String)) {
let num = tuple.0;
let string = &tuple.1;
}
But ref
is needed if you want it to be in one line.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.