Created
June 17, 2016 10:44
-
-
Save Jeweller-Tsai/eb951e68188c9c6698fb8d4f87be30d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A elixir version