Working Example
Here's a refined version of our previous example that didn't work:
fn main() {
let alfa = String::from("apple");
let bravo = alfa;
println!("alfa has {alfa}");
println!("bravo has {bravo}");
}
We can get the code working with a reference by changing the line
let bravo = alfa;
to:
let bravo = &alfa;
Here's the full sample which outputs:
alfa has apple
bravo has apple
SOURCE CODE
fn main() {
let alfa = String::from("apple");
let bravo = &alfa;
println!("alfa has {alfa}");
println!("bravo has {bravo}");
}