It looks very similar to Haskell's monadic bind operator (>>=) at first
glance.
02/10/2014 10:40 PM, Armin Ronacher пишет:
Hi,
I was playing around with the new IO system a lot and got some very
high level feedback on that. Currently the IoResult objects implement
a few traits to pass through to the included success value and to
dispatch method calls.
That's nice but it means that from looking at the code you can easily
miss that a result is involved and if you add methods you need to add
manual proxy methods on the result.
At the end of the day the only thing you actually need to pass through
is the error. So I would propose a new operator "->" that acts as a
"resolve deref" operator. It would be operating on the "Some" part of
an Option and the "Ok" part of a result and pass through the errors
unchanged:
So essentially this:
let rv = match expr() {
Ok(tmp) => tmp.method(),
err => err,
};
Would be equivalent to:
let rv = expr->method();
Likewise for options:
let rv = match expr {
Some(tmp) => tmp.method(),
None => None,
}
Would likewise be equivalent to:
let rv = expr->method();
As a result you could only ever call this on things that return
results/options themselves.
Annoyingly enough this also means that the results need to be
compatible which is still a problem. The example there would be an IO
trait that is implemented by another system that also has its own
error cases. Case in point: SSL wrapping that wants to fail with SSL
errors in addition to IO errors. I fail to understand at the moment
how library authors are supposed to deal with this.
Thoughts on this? Am I missing something entirely?
Regards,
Armin
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev
--
WBR, S. Maximov
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev