Hello friends,
After being bullied on stackoverflow, I will give it a try here. I published my first post and they make it impossible to comment on an answer, so instead of moving my answer to the comment section, the moderator deleted the post before Shepmaster got a chance to have a look at it. At the end of the road, their software is not able to solve basic user issues, leaving all the power to the almighty moderators that can do whatever they please to bully new users. My answer was long and elaborate and I was genuinely looking for a solution.
In this forum, I've had even people help me by private message, which is rare these days, as most programmers are looking for fame above anything else.
By the way the initiative of rust mentors proves that the rust team is really trying to change things up and provide real help to people without reclaiming money or public recognition.
Here is the original question's link: Link to the stackoverflow question
I can't comment on this answer but I would like Shepmaster to give a little more code and details on how he is solving the problem by using that AsErrorSource trait you mentioned.
I am not able to understand when your solution should be used, in particular the input values involved (Error types).
If you get a chance to read it Shepmaster, please delete my answer and just edit yours if possible. Thanks
Edit. Just found this implementation of Box for Error. The op is saying that Box doesn't implement Error, but from what I can find, it seems it does. Anyways, it seems that there lots of moving parts and to be honest I am completely lost at this point. I will be doing my own research and checking this question from time to time today, and I hope Shepmaster will be able to give a detailed explanation of what is going on. Basically, I would like to have a complete example. From the time we receive a Box to its conversion to &(dyn Error + 'static) and how your solution is able to avoid the overlap you talked about.
#[stable(feature = "box_error", since = "1.8.0")]
impl<T: Error> Error for Box<T> {
#[allow(deprecated, deprecated_in_future)]
fn description(&self) -> &str {
Error::description(&**self)
}
#[allow(deprecated)]
fn cause(&self) -> Option<&dyn Error> {
Error::cause(&**self)
}
fn source(&self) -> Option<&(dyn Error + 'static)> {
Error::source(&**self)
}
}
Edit, I understand what he meant by the fact that trait implements overlap. What I didn't understand is the solution that he proposed in his SNAFU error crate, basically implementing that trait does, the gist of it if you prefer.
pub trait AsErrorSource {
/// For maximum effectiveness, this needs to be called as a method
/// to benefit from Rust's automatic dereferencing of method
/// receivers.
fn as_error_source(&self) -> &(dyn Error + 'static);
}
impl AsErrorSource for dyn Error + 'static {
fn as_error_source(&self) -> &(dyn Error + 'static) {
self
}
}