1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tail: Take ownership of the provided BufReader<T>

The `BufReader` argument passed to the `fn tail<T: Read>(&mut BufReader<T>,
settings: &settings)` function is never reused, so the `tail` function should
just take ownership of it.
This commit is contained in:
Nick Fitzgerald 2016-03-19 16:03:42 -07:00
parent bbd55b283a
commit 977742f209

10
src/tail/tail.rs Normal file → Executable file
View file

@ -134,8 +134,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
let files = given_options.free;
if files.is_empty() {
let mut buffer = BufReader::new(stdin());
tail(&mut buffer, &settings);
let buffer = BufReader::new(stdin());
tail(buffer, &settings);
} else {
let mut multiple = false;
let mut firstime = true;
@ -153,8 +153,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
let path = Path::new(file);
let reader = File::open(&path).unwrap();
let mut buffer = BufReader::new(reader);
tail(&mut buffer, &settings);
let buffer = BufReader::new(reader);
tail(buffer, &settings);
}
}
@ -248,7 +248,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
(options, None)
}
fn tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) {
fn tail<T: Read>(mut reader: BufReader<T>, settings: &Settings) {
// Read through each line/char and store them in a ringbuffer that always
// contains count lines/chars. When reaching the end of file, output the
// data in the ringbuf.