Creating references in Rust
References are really easy to create. You use the reference operator, when assigning your variable. The reference operator is an ampersand. The ampersand goes in front of the variable you are using when you re-assign the string reference. For example:
let my_var = String::from("My String");
let my_var_b = &my_var;
There are some differences between String slices and String references. A String slice is &str. Whereas A String reference is &String.
You can coerce a string reference into a string slice (called deref coercion), since the String reference has access to all the information store on the heap to understand the underlying data - but this cannot be done the other way around. String slices cannot perform the same coercion.
This means that if a function is expecting a String slice for example, you can pass a String::from reference into it, since the compiler can coerce the string into a string slice itself.