> Out of curiosity, why not make File::open() return a Result<> instead of
> Option<> like it does now?

This is a relic of I/O using conditions. The idea here is that if you
wanted to catch the condition, you can indeed catch it (and do
something appropriate). If you don't catch it then the task fails and
there's no need to return an Option anyway. The other idea here is
that because the error is signaled by the condition, the return value
of the function can be something that's "always successful".

In this case the definition of success is returning something which is
a Reader/Seek. The I/O library provides an implementation of
Reader/Seek on Option<T: Reader>, so in cases where we can't actually
return a reader (because of the error), None is returned.

The motivation behind this strategy is to reduce boilerplate code
necessary for handling errors in I/O. Instead if checking for errors
at each operation you can check for errors during a block of
operations (or at least I believe that's the idea).

All that being said, it's likely that conditions will be removed from
the api so the return value will indeed be Result<File, IoError> as
one might expect. This is still a little in flux now (mostly on the
error portion of the result), and as a consequence this means that
almost any I/O operation will be Result<T, Error>.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to