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

12
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; let files = given_options.free;
if files.is_empty() { if files.is_empty() {
let mut buffer = BufReader::new(stdin()); let buffer = BufReader::new(stdin());
tail(&mut buffer, &settings); tail(buffer, &settings);
} else { } else {
let mut multiple = false; let mut multiple = false;
let mut firstime = true; let mut firstime = true;
@ -153,8 +153,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
let path = Path::new(file); let path = Path::new(file);
let reader = File::open(&path).unwrap(); let reader = File::open(&path).unwrap();
let mut buffer = BufReader::new(reader); let buffer = BufReader::new(reader);
tail(&mut buffer, &settings); tail(buffer, &settings);
} }
} }
@ -169,7 +169,7 @@ fn parse_size(mut size_slice: &str) -> Option<usize> {
} else { } else {
1024usize 1024usize
}; };
let exponent = let exponent =
if size_slice.len() > 0 { if size_slice.len() > 0 {
let mut has_suffix = true; let mut has_suffix = true;
let exp = match size_slice.chars().last().unwrap_or('_') { let exp = match size_slice.chars().last().unwrap_or('_') {
@ -248,7 +248,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
(options, None) (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 // 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 // contains count lines/chars. When reaching the end of file, output the
// data in the ringbuf. // data in the ringbuf.