▲ 13 r/learnrust
Why does one work and the other doesn't?
fn main() {
let mut s = String::from("hello world");
let x = *get_unrelated_int(&s); // compiles
let x = get_unrelated_int(&s); // doesn't
s.clear();
println!("{x}");
}
fn get_unrelated_int(_s: &String) -> &i32 {
&42
}
u/great_escape_fleur — 6 days ago