Confused on what to use when or if it's purely preferential for string instantiation?

144 points 10K_Samael 57 comments

Between:

String::from("this_is_a_string")

"this_is_a_string".to_owned()

"this_is_a_string".to_string()

is there any difference even per use-case? I find the .to_string() the most ergonomic.

Edit: thank you all, everyone is well intentioned, insightful and kind in the replies. I definitely learned multiple things from you, and as my first experience participating in the rust community this is extremely encouraging to me.