This is an ergonomics question, above all.
Consider this code:
fn test<R, F, Err>(func: F) -> Result<R, Err>
where F: FnOnce() -> Result<R, Err>
{
func()
}
fn main() {
let result = test(|| Ok("yes")).unwrap();
println!("{result}");
}
It won't work unless I turn this:
test(|| Ok("yes"))
into this:
test(||->Result<&str, ()> { Ok("yes") })
How can this be made nicer to use?
- I don't want to give up a generic error type, because it's needed in a minority of cases
- But the majority of cases will never use the error at all and shouldn't have to specify it
Defaults are illegal in function generics... For some reason(s) that even some doyens of early Rust don't seem to know... but the feature to bring them back seems like it died.
So is there a clever idea I'm not seeing?
Thanks for any thoughts.