What is the best practice for converting Option<&str>
to Option<String>
? Strictly speaking, I am looking for a short equivalent:
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()))
source share