Is using `ref` in a function argument the same as automatically taking a reference?

rust

Solution

The value is copied, and the copy is then referenced.

fn f(ref mut x: i32) {
    *x = 12;
}

fn main() {
    let mut x = 42;
    f(x);
    println!("{}", x);
}

Output: 42

Problem

Rust tutorials often advocate passing an argument by reference: ``` fn my_func(x: &Something) ``` This makes it necessary to explicitly take a reference of the value at the call site: ``` my_func(&my_value). ``` It is possible to use the `ref` keyword usually used in pattern matching: ``` fn my_func(ref x: Something) ``` I can call this by doing ``` my_func(my_value) ``` Memory-wise, does this work like I expect or does it copy `my_value` on the stack before calling `my_func` and then get a reference to the copy?

Original source