Hi,
I am trying to format (log/print) an Option<String>
, or an alternative value if the Option is None
. I am basically running into the same thing as this thread from 2016: &Option<String> to Option<&str>
I am wondering if anything has changed since then? The way I've found to appease the compiler is still pretty ugly:
log::error!("foo {}",
myoption.map(|s| &s as _).unwrap_or("none-case string"));
Or perhaps more horrifically,
log::error!("foo {}",
(myoption.into() as Option<&str>).unwrap_or("none-case string"));
What's idiomatic? Thanks.