2 ms·
> Is Result not just a specialised Either? In what way is Either inferior? It's better named when it comes to being a value/error union: Result/Ok/Err is somew
by masklinn 12y ago
> Is Result not just a specialised Either? In what way is Either inferior?
It's better named when it comes to being a value/error union: Result/Ok/Err is somewhat more obvious than Either/Right/Left, especially for people who don't make the connection between "right" and "correct".
Aside from that, Result was annotated with #[must_use], so the compiler will warn if you ignore a Result return value:
fn main() {
f1();
}
fn f1() -> Result<(), ()> {
Ok(())
}
=>
> rustc test.rs
test.rs:2:5: 2:10 warning: unused result which must be used, #[warn(unused_must_use)] on by default
test.rs:2 f1();
^~~~~
doing that with Either would be weird.
Those are not huge, but they're small tweaks specially making Result a better fit for an exception replacement.