-
| I'd like to implement compose_me use push_str, but as the log shows, I failed. However, even use func push to push a char 'a' no effect. Is there anything wrong? |
Beta Was this translation helpful? Give feedback.
Answered by temanmd Feb 19, 2025
Replies: 1 comment 1 reply
-
| When you do fn compose_me(input: &str) -> String { ... input.to_string().push_str(a); ... }then you call
Note that the type returned here is already a let input = String::from(input); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by mo8it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
When you do
to_string()here:then you call
push_stron a newString(returned fromto_string()function call), not oninput.inputalready has theStringtype, you don't have to convert it again, just removeto_string()to directly modifyinput.Note that the type returned here is already a
String: