Out of curiosity, why not make File::open() return a Result<> instead of
Option<> like it does now? The current implementation already seems to be
matching against the result of fs_open() and returning None if the result
is Err(). So why the extra level of indirection and raising a condition in
that case?


--
Ziad


On Sat, Nov 2, 2013 at 10:42 PM, Alex Crichton <[email protected]> wrote:

> This api is a little in flux (hopefully #10179 will land soon), but
> I'm not quite sure what you mean about keeping the file descriptor
> open. If there was an error opening the file, then a file descriptor
> was never allocated and there's nothing to keep open. Regardless, once
> my pull request lands, your example would look something like:
>
> use std::rt::io;
> use std::rt::io::File;
>
> match io::result(|| File::open(&Path::new("/some/path")) {
>   Ok(file) => { /* file was successfully opened, it existed */ }
>   Err(e) => { /* file couldn't be opened, error contained in e */ }
> }
>
> On Sat, Nov 2, 2013 at 5:34 PM, John Mija <[email protected]> wrote:
> > How to check an error at opening a file but without closing its file
> > descriptor?
> >
> > use std::path;
> > use std::rt::io;
> > use std::rt::io::file;
> >
> > let filename = "/some/path";
> > let f = file::open(&path::Path::new(filename), io::Open, io::Read);
> > _______________________________________________
> > Rust-dev mailing list
> > [email protected]
> > https://mail.mozilla.org/listinfo/rust-dev
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to