What is the idiomatic way to convert &str to String?

I'd say pick the one that best expresses the context in which you're trying to use it:

  • to_owned if you need a stronger level of access to it
  • to_string if you really want a string in particular
  • .into() if you're calling a function that needs something not quite what you have
  • etc
1 Like