I'm new to Rust and trying to understand how reference works. Below is a simple function.
fn f1(x: &i32) -> &i32{
x
}
Since x is of type &i32, return it directly matches the return type &i32. But I found that if I change the function to this, it also compiles without any problem:
fn f1(x: &i32) -> &i32{
&x
}
Here x is of type &i32, &x is of type &&i32 and doesn't match the return type &i32. Why it compiles?