Experimenting on 09_strings/strings1.rs #2184
-
fn current_favorite_color() -> str {
"blue"
}
fn main() {
let answer = current_favorite_color();
println!("My current favorite color is {answer}");
} why the above code doesn't work?. |
Beta Was this translation helpful? Give feedback.
Answered by
mo8it
Jan 2, 2025
Replies: 1 comment
-
String literals like |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mo8it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
String literals like
"blue"
have the type&str
. You can think of them as being borrowed from a fixed space in memory, but they are valid until the program terminates. You need to change the return type to&str
.