Hi Alex,

I had seen an example at http://static.rust-lang.org/doc/master/std/rt/io/file/fn.open.html which closes the file at the end of a block.

I simply wants to open a file, checking if there is any error, for later to can read it line by line until the end of file. I was wrong using the term "closing its file descriptor".

El 03/11/13 05:42, Alex Crichton escribió:
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

Reply via email to