I am new to rust and still trying to grab the concept of it. In Error trait docs it mentions
Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>
But why Result is defined as Result<T,E> instead of Result<T,E:Error> to make it clearer?
Result, it works perfectly well with things which don't implementErroritself..binary_search()which returnsResult<usize, usize>Rc::try_unwrap, which consume the value, try to convert it to something else and return the original value in case of error.Resultlike that. I suspect you might be thinking too much about exceptions in some other languages.Eis not required to implementError, the aforementioned cases are actually a design mistake (at leasttry_unwrap()). The error type should at least implementDebug, so thatunwrap()andexpect()can work. A better candidate isBox<dyn Error>(or other variants such asanyhow::Error, which is an error type but does not implementError.