S
S
sectronix2015-04-14 15:59:43
Rust
sectronix, 2015-04-14 15:59:43

Why doesn't try! with File::open?

I'm trying to compile an example:

use std::fs::File;

fn main() {
    let f = try!(File::open("in.txt"));
}

But, it crashes with an error
<std macros>:5:8: 6:42 error: mismatched types:
 expected `()`,
    found `core::result::Result<_, _>`
(expected (),
    found enum `core::result::Result`) [E0308]
<std macros>:5 return $ crate:: result:: Result:: Err (
<std macros>:6 $ crate:: convert:: From:: from ( err ) ) } } )
<std macros>:1:1: 6:48 note: in expansion of try!
sum.rs:4:13: 4:39 note: expansion site
error: aborting due to previous error

Version 1.0.0-nightly (47def3ef2 2015-04-13) (built 2015-04-12)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sectronix, 2015-04-15
@sectronix

Found the answer to this question: https://www.reddit.com/r/rust/comments/2z8p4t/stdf...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question