I have a function that returns an Option<> result. I would like to print it with a fallback like this:
println!("Result: {}", result.map_or("not found", |r| r.to_string()));
Unfortunately, this way I either:
- get a
&'static strvsStringtype error, - or get a "does not live long enough" if I do
&r.to_string(), - or have to convert
"not found"to aStringwhich is ugly and seems very unnecessary.
Is there a way to do this conversion while keeping the default value an &'static str?