Re:Rust can be difficult to learn and frustrating, but it's ...
by rqs on Tuesday October 23, 2018 @02:38AM
(#18281203)
> you could define the equivalent of Go error in Rust as a trait and box it (ie. a trait object).
I know this basically how Go's error handling works (Put error data on heap and pass the reference), but I'm not fan of it (the put data on heap part of it) too :(
I will try out the error-chain, thank you for reminding me that.
Re:Rust can be difficult to learn and frustrating, but it's ...
by steveklabnik on Tuesday October 23, 2018 @01:43PM
(#18285586)
The “failure” crate is an alternative to error-chain as well.
Well there's stuff like error-chain to take care of the boilerplate...
Also, I believe you could define the equivalent of Go error in Rust as a trait and box it (ie. a trait object). It could be used much the same way as in Go with the additional benefit of Result being a sum type. I'm personally not a big fan of this approach but I guess it might work...