If you use some libraries every library brings its own error type. These error types then lie outside of your crate therefore you can't coerce them with the ? operator in one function scope. You therefore then create your own enum type or struct that then implements From for all the error types (and of course std::error::Error) The problem is when you simply want to return a result:
One solution is to call lib2::foo().map_error(MyError::From). But this is very wordy and could be very well done by the compiler. We just need a way to tell the compiler that he needs to use the From implementation.
My current solution is an extention function for Result:
fn auto_err<F>(self) -> Result<T, F>
where F: From<E>;
This helps a lot to reduce the boilerplate of obvious from into conversions. It might even be worth a keyword but that's debatable.
When it's chosen to get a keyword I would suggest the postfix !
The sample code above with the operator would look like this:
That could be nice, but it conflicts with the core impl<T> From<T> for T;
The possibility of a helper method was tried in rfc 1996 but finally discarded because of lack of motivation in the success conversion.
In that RFC thread @withoutboats comments about the possibility of implementing the trait:
Someday it will work (because we want intersection impl specialization as soon as its feasible to implement it), and the impl should exist so that you can use it generically.
That was in 2017, I have no idea what that "someday" would be.