I’m completely new to Rust and currently working my way through “The Book”.
While reading the Chapter on Strings and the invocation of
push_str, I got confused about the syntax when invoking a function that takes a string slice as parameter.
Say we have a function
fn foo(s: &str) and define a variable
let x = "Hello World";.
Are these function calls all equivalent to each other? If so, why?
foo(x); // 1 foo(&x); // 2 foo(&x[..]); // 3
x already is of type
&str, why does 2 work?