I just want to include something optional in a format expression, each time I do it I end up finding a different way because I haven't found one I'm happy with.
// here's the most basic form, when it works, it's great
let o: Option<&str> = Some("some");
assert_eq!(
format!("format {}", o.unwrap_or_default()),
"format some");
// unfortunately, if `o: !Copy` that would consume `o`, which I might not want so it becomes a bit longer
let o: Option<String> = Some("some".to_string());
assert_eq!(
format!("format {}", o.as_ref().map(String::as_str).unwrap_or_default()),
"format some");
// if I want to get rid of that extra space on `None` then it becomes really ugly
let o: Option<String> = None;
assert_eq!(
format!("format{}", o.as_ref().map(|s| format!(" {}", s)).as_ref().map(String::as_str).unwrap_or_default()),
"format");