Conversion from Option<&str> to Option<String>

rust

Solution

`map` is a better choice:

s.map(|s| s.to_string())

or

s.map(str::to_string)

Problem

What is the best practice to convert `Option<&str>` to `Option<String>`? Strictly speaking I'm looking for a concise equivalent of: ``` if s.is_some() { Some(s.to_string()) } else { None } ``` and this is the best I could come up with: ``` s.and_then(|s| Some(s.to_string())) ```

Original source