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()))