Skip to content

Instantly share code, notes, and snippets.

@ruimo
Created May 10, 2017 23:50
Show Gist options
  • Save ruimo/aebf1a5a3bb5f9d69d48d89d8b81a500 to your computer and use it in GitHub Desktop.
Save ruimo/aebf1a5a3bb5f9d69d48d89d8b81a500 to your computer and use it in GitHub Desktop.
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
fn tail() -> io::Result<String> {
BufReader::new(File::open("/tmp/foo.txt")?).lines().last().unwrap_or(Ok(String::new()))
}
fn main() {
match tail() {
Ok(line) => println!("{}", line),
Err(e) => println!("! {:?}", e.kind())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment