Hacker News new | past | comments | ask | show | jobs | submit login

> How does it know how to create your Error enum? I guess it's from the #[from]? 2.

#[from] is just a convenience library feature, in reality it’s because of the From conversion trait which ? invokes on the way out. Essentially it calls ReturnType::from(ValueType) to bridge the two.

> What happens if your method tries to return something that's not an io::Error or a gz::Error? I guess the compiler catches that?

If there is no available conversion to the return error type, compilation fails.

> How would you handle doing this for multiple methods in the same file? Would you rename your enum to DecompError or something to avoid conflicts?

That is an option, although the slightly sad truth is libraries usually have a single big error type and every function returns that.

Convenient fine grained errors in rust remains unsolved, as far as I know. You can do it but it’s a lot of manual work.




Great, thanks for the reply!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: