On 11/01/2013 08:22 PM, Brian Anderson wrote:
My first reaction is that it's not obvious the difference between
`is_ok` and `ok`. Also, it would seem that `ok()` is required to
return a different type to make this work, which seems fairly
burdensome. If it *is* required to return a different type, then the
obvious thing to do is just transform it into `Option<T>` which is
fairly nice since it just defers the problem to `Option` completely.
The idea is that for example for `res: Result<T, E>`, `res.ok()` returns
`Option<T>` and `res.err()` returns `Option<E>`. So yes, it would just
defer to Option.
About the difference between `is_ok` and `ok` - fair enough. However I
think the only way to make this more clear is to rename `ok()` and
`err()` to something longer, which would make the chaining more verbose
and has the problem that all short words that would fit are already
heavily overloaded in rust terminology:
- `as_ok()` and `as_err()`
- `to_ok()` and `to_err()`
- `get_ok()` and `get_err()`
- `ok_get()` and `err_get()`
Maybe a abbreviation of variant would work:
- `ok_var()` and `err_var()`
Seems to read nice at least:
~~~
res.ok_var().get();
res.err_var().get();
res.err_var().expect("...");
~~~
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev