News for hackers. Stuff that matters.
Re:Rust can be difficult to learn and frustrating, but it's ... by steveklabnik on Monday October 22, 2018 @11:33PM (#18280542)
Traits for interop are a prime consideration for std, even if we try to keep it small. But we can only add things when they’re ready; that’s part of the stability you desire.

Look at the Future trait, as an example. And rust has had the equivalent of io.{Reader, Writer} since 1.0.

Re:Rust can be difficult to learn and frustrating, but it's ... by rqs on Tuesday October 23, 2018 @02:13AM (#18281088)
I know. But for me personally, the `io::Reader` and `io::Writer` is still not comfortable enough. Mainly because it's return values, `io::Error` to be specific. Because I found that in many of my cases, predefined `io::ErrorKind` is not enough for me, this results my abuse of `io::ErrorKind::Other`.

In Go, `error` is an interface that can later be asserted, so I can return any `error` then deal with them as late as I need.

This gives me ability to write some complex `io.Reader` and `io.Writer`. For example, an `io.Reader` that can Decode data stream, and returns both CodecError and IoError when it encountered any.

In Rust, if I want to write a similar thing, a HPACK decoder that returns both `io::Error` and `HPACK::DecodeError` for example, I need come up with another `Result` type that wraps both errors. This can sometime be tiring and makes the code inflexible (As one simple change to the `Result` may effect the entire call chain up and down).

BUT ... Maybe it's Go's fault, it treats me too well, make me want something that I cannot have for free (performance cost) else where.

Re:Rust can be difficult to learn and frustrating, but it's ... by piano on Tuesday October 23, 2018 @02:22AM (#18281130)
> In Rust, if I want to write a similar thing, a HPACK decoder that returns both `io::Error` and `HPACK::DecodeError` for example, I need come up with another `Result` type that wraps both errors. This can sometime be tiring and makes the code inflexible (As one simple change to the `Result` may effect the entire call chain up and down).

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...

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.