From 768ed71725f548ad08882b8780d05eed8037b1f0 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sat, 28 Dec 2019 12:49:58 -0600 Subject: [PATCH] refactor/polish ~ fix `cargo clippy` complaints (use b'...' notation) --- src/ls/ls.rs | 2 +- src/mktemp/mktemp.rs | 6 +++--- src/unexpand/unexpand.rs | 6 +++--- src/uniq/uniq.rs | 2 +- src/wc/wc.rs | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ls/ls.rs b/src/ls/ls.rs index a518a6599..11d6c054d 100644 --- a/src/ls/ls.rs +++ b/src/ls/ls.rs @@ -336,7 +336,7 @@ fn display_dir_entry_size(entry: &PathBuf, options: &getopts::Matches) -> (usize fn pad_left(string: String, count: usize) -> String { if count > string.len() { let pad = count - string.len(); - let pad = String::from_utf8(vec![' ' as u8; pad]).unwrap(); + let pad = String::from_utf8(vec![b' ' as u8; pad]).unwrap(); format!("{}{}", pad, string) } else { string diff --git a/src/mktemp/mktemp.rs b/src/mktemp/mktemp.rs index c5747385a..04d293620 100644 --- a/src/mktemp/mktemp.rs +++ b/src/mktemp/mktemp.rs @@ -179,9 +179,9 @@ pub fn dry_exec(mut tmpdir: PathBuf, prefix: &str, rand: usize, suffix: &str) -> rand::thread_rng().fill(bytes); for byte in bytes.iter_mut() { *byte = match *byte % 62 { - v @ 0..=9 => (v + '0' as u8), - v @ 10..=35 => (v - 10 + 'a' as u8), - v @ 36..=61 => (v - 36 + 'A' as u8), + v @ 0..=9 => (v + b'0' as u8), + v @ 10..=35 => (v - 10 + b'a' as u8), + v @ 36..=61 => (v - 36 + b'A' as u8), _ => unreachable!(), } } diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 076a68fee..2cee398dd 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -189,13 +189,13 @@ fn write_tabs( break; } - safe_unwrap!(output.write_all("\t".as_bytes())); + safe_unwrap!(output.write_all(b"\t")); scol += nts; } } while col > scol { - safe_unwrap!(output.write_all(" ".as_bytes())); + safe_unwrap!(output.write_all(b" ")); scol += 1; } } @@ -219,7 +219,7 @@ fn unexpand(options: Options) { for file in options.files.into_iter() { let mut fh = open(file); - while match fh.read_until('\n' as u8, &mut buf) { + while match fh.read_until(b'\n' as u8, &mut buf) { Ok(s) => s > 0, Err(_) => !buf.is_empty(), } { diff --git a/src/uniq/uniq.rs b/src/uniq/uniq.rs index ed73a2785..83112a60b 100644 --- a/src/uniq/uniq.rs +++ b/src/uniq/uniq.rs @@ -99,7 +99,7 @@ impl Uniq { if self.zero_terminated { 0 } else { - '\n' as u8 + b'\n' as u8 } } diff --git a/src/wc/wc.rs b/src/wc/wc.rs index 67c120e93..dbe74c6e4 100644 --- a/src/wc/wc.rs +++ b/src/wc/wc.rs @@ -121,10 +121,10 @@ pub fn uumain(args: Vec) -> i32 { 0 } -const CR: u8 = '\r' as u8; -const LF: u8 = '\n' as u8; -const SPACE: u8 = ' ' as u8; -const TAB: u8 = '\t' as u8; +const CR: u8 = b'\r'; +const LF: u8 = b'\n'; +const SPACE: u8 = b' '; +const TAB: u8 = b'\t'; const SYN: u8 = 0x16 as u8; const FF: u8 = 0x0C as u8;