Skip to content

Instantly share code, notes, and snippets.

@Jeweller-Tsai
Created June 17, 2016 10:44
Show Gist options
  • Save Jeweller-Tsai/eb951e68188c9c6698fb8d4f87be30d7 to your computer and use it in GitHub Desktop.
Save Jeweller-Tsai/eb951e68188c9c6698fb8d4f87be30d7 to your computer and use it in GitHub Desktop.
use std::io::{BufReader,BufRead};
use std::fs::File;
use std::time::Duration;
use std::thread;
use std::env;
fn main() {
fn tail(reader: &mut BufReader<&File>) {
let time = Duration::from_millis(10);
loop {
let mut line = String::new();
reader.read_line(&mut line).unwrap();
if line == "" {
thread::sleep(time);
} else {
print!("{}", line);
}
}
}
let path = &env::args().nth(1).unwrap();
match File::open(path) {
Ok(file) => {
let mut reader = BufReader::new(&file);
tail(&mut reader);
},
Err(e) => {
println!("{}", e);
}
}
}
@Jeweller-Tsai
Copy link
Author

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