Skip to content

Instantly share code, notes, and snippets.

@sbp
Created March 4, 2015 11:48
Show Gist options
  • Save sbp/95ad1f2ba51ef6bd523c to your computer and use it in GitHub Desktop.
Save sbp/95ad1f2ba51ef6bd523c to your computer and use it in GitHub Desktop.
Fails: Get len of a file, using rustc 1.0.0-dev (built 2015-02-22)
use std::io::prelude::*;
use std::fs::File;
use std::fs::Metadata;
fn main() {
fn len() -> std::io::Result<()> {
let mut f = try!(File::open("len.rs"));
println!("{}", f.metadata().len());
Ok(())
}
}
$ rustc len.rs
len.rs:8:37: 8:42 error: type `core::result::Result<std::fs::Metadata, std::io::error::Error>` does not implement any method in scope named `len`
len.rs:8 println!("{}", f.metadata().len());
^~~~~
error: aborting due to previous error
@sbp
Copy link
Author

sbp commented Mar 4, 2015

Please comment here if you can fix this issue.

@sbp
Copy link
Author

sbp commented Mar 6, 2015

According to klutzy, the answer was try!(f.metadata()).len()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment