mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (avoid as ...
)
This commit is contained in:
parent
66124454e3
commit
d343d533ba
13 changed files with 38 additions and 38 deletions
|
@ -216,7 +216,7 @@ fn convert_size_human(size: u64, multiplier: u64, _block_size: u64) -> String {
|
|||
}
|
||||
|
||||
fn convert_size_b(size: u64, _multiplier: u64, _block_size: u64) -> String {
|
||||
format!("{}", ((size as f64) / (1 as f64)).ceil())
|
||||
format!("{}", ((size as f64) / (1_f64)).ceil())
|
||||
}
|
||||
|
||||
fn convert_size_k(size: u64, multiplier: u64, _block_size: u64) -> String {
|
||||
|
|
|
@ -169,7 +169,7 @@ fn expand(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', &mut buf) {
|
||||
Ok(s) => s > 0,
|
||||
Err(_) => buf.is_empty(),
|
||||
} {
|
||||
|
|
|
@ -128,7 +128,7 @@ fn mkdir(path: &Path, recursive: bool, mode: u16, verbose: bool) -> i32 {
|
|||
use fs::{Permissions, set_permissions};
|
||||
use std::os::unix::fs::{PermissionsExt};
|
||||
|
||||
let mode = Permissions::from_mode(mode as u32);
|
||||
let mode = Permissions::from_mode(u32::from(mode));
|
||||
|
||||
if let Err(err) = set_permissions(path, mode) {
|
||||
show_error!(
|
||||
|
|
|
@ -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 + b'0' as u8),
|
||||
v @ 10..=35 => (v - 10 + b'a' as u8),
|
||||
v @ 36..=61 => (v - 36 + b'A' as u8),
|
||||
v @ 0..=9 => (v + b'0'),
|
||||
v @ 10..=35 => (v - 10 + b'a'),
|
||||
v @ 36..=61 => (v - 36 + b'A'),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,9 +133,9 @@ impl<'a> MemoryDecoder<'a> {
|
|||
/// Returns a u8/u16/u32/u64 from the internal buffer at position `start`.
|
||||
pub fn read_uint(&self, start: usize, byte_size: usize) -> u64 {
|
||||
match byte_size {
|
||||
1 => self.data[start] as u64,
|
||||
2 => self.byte_order.read_u16(&self.data[start..start + 2]) as u64,
|
||||
4 => self.byte_order.read_u32(&self.data[start..start + 4]) as u64,
|
||||
1 => u64::from(self.data[start]),
|
||||
2 => u64::from(self.byte_order.read_u16(&self.data[start..start + 2])),
|
||||
4 => u64::from(self.byte_order.read_u32(&self.data[start..start + 4])),
|
||||
8 => self.byte_order.read_u64(&self.data[start..start + 8]),
|
||||
_ => panic!("Invalid byte_size: {}", byte_size),
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ impl<'a> MemoryDecoder<'a> {
|
|||
2 => f64::from(f16::from_bits(
|
||||
self.byte_order.read_u16(&self.data[start..start + 2]),
|
||||
)),
|
||||
4 => self.byte_order.read_f32(&self.data[start..start + 4]) as f64,
|
||||
4 => f64::from(self.byte_order.read_f32(&self.data[start..start + 4])),
|
||||
8 => self.byte_order.read_f64(&self.data[start..start + 8]),
|
||||
_ => panic!("Invalid byte_size: {}", byte_size),
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ fn format_flo32(f: f32) -> String {
|
|||
// subnormal numbers will be normal as f64, so will print with a wrong precision
|
||||
format!("{:width$e}", f, width = width) // subnormal numbers
|
||||
} else {
|
||||
format_float(f as f64, width, precision)
|
||||
format_float(f64::from(f), width, precision)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ pub fn arrnum_int_mult(arr_num: &[u8], basenum: u8, base_ten_int_fact: u8) -> Ve
|
|||
let mut carry: u16 = 0;
|
||||
let mut rem: u16;
|
||||
let mut new_amount: u16;
|
||||
let fact: u16 = base_ten_int_fact as u16;
|
||||
let base: u16 = basenum as u16;
|
||||
let fact: u16 = u16::from(base_ten_int_fact);
|
||||
let base: u16 = u16::from(basenum);
|
||||
|
||||
let mut ret_rev: Vec<u8> = Vec::new();
|
||||
let mut it = arr_num.iter().rev();
|
||||
|
@ -11,7 +11,7 @@ pub fn arrnum_int_mult(arr_num: &[u8], basenum: u8, base_ten_int_fact: u8) -> Ve
|
|||
let i = it.next();
|
||||
match i {
|
||||
Some(u) => {
|
||||
new_amount = ((*u as u16) * fact) + carry;
|
||||
new_amount = (u16::from(*u) * fact) + carry;
|
||||
rem = new_amount % base;
|
||||
carry = (new_amount - rem) / base;
|
||||
ret_rev.push(rem as u8)
|
||||
|
@ -54,8 +54,8 @@ pub fn arrnum_int_div_step(
|
|||
};
|
||||
|
||||
let mut bufferval: u16 = 0;
|
||||
let base: u16 = radix_in as u16;
|
||||
let divisor: u16 = base_ten_int_divisor as u16;
|
||||
let base: u16 = u16::from(radix_in);
|
||||
let divisor: u16 = u16::from(base_ten_int_divisor);
|
||||
let mut traversed = 0;
|
||||
|
||||
let mut quotient = 0;
|
||||
|
@ -64,9 +64,9 @@ pub fn arrnum_int_div_step(
|
|||
let mut it_f = refd_vals.iter();
|
||||
loop {
|
||||
let u = match it_replace.next() {
|
||||
Some(u_rep) => *u_rep as u16,
|
||||
Some(u_rep) => u16::from(*u_rep),
|
||||
None => match it_f.next() {
|
||||
Some(u_orig) => *u_orig as u16,
|
||||
Some(u_orig) => u16::from(*u_orig),
|
||||
None => {
|
||||
if !after_decimal {
|
||||
break;
|
||||
|
@ -167,7 +167,7 @@ pub fn arrnum_int_add(arrnum: &[u8], basenum: u8, base_ten_int_term: u8) -> Vec<
|
|||
let mut carry: u16 = u16::from(base_ten_int_term);
|
||||
let mut rem: u16;
|
||||
let mut new_amount: u16;
|
||||
let base: u16 = basenum as u16;
|
||||
let base: u16 = u16::from(basenum);
|
||||
|
||||
let mut ret_rev: Vec<u8> = Vec::new();
|
||||
let mut it = arrnum.iter().rev();
|
||||
|
@ -175,7 +175,7 @@ pub fn arrnum_int_add(arrnum: &[u8], basenum: u8, base_ten_int_term: u8) -> Vec<
|
|||
let i = it.next();
|
||||
match i {
|
||||
Some(u) => {
|
||||
new_amount = (*u as u16) + carry;
|
||||
new_amount = u16::from(*u) + carry;
|
||||
rem = new_amount % base;
|
||||
carry = (new_amount - rem) / base;
|
||||
ret_rev.push(rem as u8)
|
||||
|
@ -224,17 +224,17 @@ pub fn base_conv_float(src: &[u8], radix_src: u8, radix_dest: u8) -> f64 {
|
|||
// of how it would work.
|
||||
let mut result: Vec<u8> = Vec::new();
|
||||
result.push(0);
|
||||
let mut factor: f64 = 1.;
|
||||
let radix_src_float: f64 = radix_src as f64;
|
||||
let mut factor: f64 = 1_f64;
|
||||
let radix_src_float: f64 = f64::from(radix_src);
|
||||
let mut i = 0;
|
||||
let mut r: f64 = 0 as f64;
|
||||
let mut r: f64 = 0_f64;
|
||||
for u in src {
|
||||
if i > 15 {
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
factor /= radix_src_float;
|
||||
r += factor * (*u as f64)
|
||||
r += factor * f64::from(*u)
|
||||
}
|
||||
r
|
||||
}
|
||||
|
@ -287,9 +287,9 @@ pub trait RadixDef {
|
|||
}
|
||||
pub struct RadixTen;
|
||||
|
||||
const ZERO_ASC: u8 = '0' as u8;
|
||||
const UPPER_A_ASC: u8 = 'A' as u8;
|
||||
const LOWER_A_ASC: u8 = 'a' as u8;
|
||||
const ZERO_ASC: u8 = b'0';
|
||||
const UPPER_A_ASC: u8 = b'A';
|
||||
const LOWER_A_ASC: u8 = b'a';
|
||||
|
||||
impl RadixDef for RadixTen {
|
||||
fn get_max(&self) -> u8 {
|
||||
|
|
|
@ -297,7 +297,7 @@ fn prompt(msg: &str) -> bool {
|
|||
let stdin = stdin();
|
||||
let mut stdin = stdin.lock();
|
||||
|
||||
match stdin.read_until('\n' as u8, &mut buf) {
|
||||
match stdin.read_until(b'\n', &mut buf) {
|
||||
Ok(x) if x > 0 => match buf[0] {
|
||||
b'y' | b'Y' => true,
|
||||
_ => false,
|
||||
|
|
|
@ -25,7 +25,7 @@ impl BirthTime for Metadata {
|
|||
self.created()
|
||||
.ok()
|
||||
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
|
||||
.map(|e| pretty_time(e.as_secs() as i64, e.subsec_nanos() as i64))
|
||||
.map(|e| pretty_time(e.as_secs() as i64, i64::from(e.subsec_nanos())))
|
||||
.unwrap_or_else(|| "-".to_owned())
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ impl FsMeta for Sstatfs {
|
|||
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "linux"))]
|
||||
fn fsid(&self) -> u64 {
|
||||
let f_fsid: &[u32; 2] = unsafe { transmute(&self.f_fsid) };
|
||||
(f_fsid[0] as u64) << 32 | f_fsid[1] as u64
|
||||
(u64::from(f_fsid[0])) << 32 | u64::from(f_fsid[1])
|
||||
}
|
||||
#[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "linux")))]
|
||||
fn fsid(&self) -> u64 {
|
||||
|
|
|
@ -31,7 +31,7 @@ fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
|
|||
blocks_read += 1;
|
||||
for &byte in buf[..n].iter() {
|
||||
checksum = (checksum >> 1) + ((checksum & 1) << 15);
|
||||
checksum = checksum.wrapping_add(byte as u16);
|
||||
checksum = checksum.wrapping_add(u16::from(byte));
|
||||
}
|
||||
}
|
||||
_ => break,
|
||||
|
@ -51,7 +51,7 @@ fn sysv_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
|
|||
Ok(n) if n != 0 => {
|
||||
blocks_read += 1;
|
||||
for &byte in buf[..n].iter() {
|
||||
ret = ret.wrapping_add(byte as u32);
|
||||
ret = ret.wrapping_add(u32::from(byte));
|
||||
}
|
||||
}
|
||||
_ => break,
|
||||
|
|
|
@ -48,7 +48,7 @@ struct Settings {
|
|||
impl Default for Settings {
|
||||
fn default() -> Settings {
|
||||
Settings {
|
||||
mode: FilterMode::Lines(10, '\n' as u8),
|
||||
mode: FilterMode::Lines(10, b'\n'),
|
||||
sleep_msec: 1000,
|
||||
beginning: false,
|
||||
follow: false,
|
||||
|
@ -63,7 +63,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
// handle obsolete -number syntax
|
||||
let options = match obsolete(&args[1..]) {
|
||||
(args, Some(n)) => {
|
||||
settings.mode = FilterMode::Lines(n, '\n' as u8);
|
||||
settings.mode = FilterMode::Lines(n, b'\n');
|
||||
args
|
||||
}
|
||||
(args, None) => args,
|
||||
|
@ -146,7 +146,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
slice = &slice[1..];
|
||||
}
|
||||
match parse_size(slice) {
|
||||
Ok(m) => settings.mode = FilterMode::Lines(m, '\n' as u8),
|
||||
Ok(m) => settings.mode = FilterMode::Lines(m, b'\n'),
|
||||
Err(e) => {
|
||||
show_error!("{}", e.description());
|
||||
return 1;
|
||||
|
@ -326,7 +326,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<u64>) {
|
|||
let current = options[a].clone();
|
||||
let current = current.as_bytes();
|
||||
|
||||
if current.len() > 1 && current[0] == '-' as u8 {
|
||||
if current.len() > 1 && current[0] == b'-' {
|
||||
let len = current.len();
|
||||
for pos in 1..len {
|
||||
// Ensure that the argument is only made out of digits
|
||||
|
|
|
@ -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(b'\n' as u8, &mut buf) {
|
||||
while match fh.read_until(b'\n', &mut buf) {
|
||||
Ok(s) => s > 0,
|
||||
Err(_) => !buf.is_empty(),
|
||||
} {
|
||||
|
|
|
@ -99,7 +99,7 @@ impl Uniq {
|
|||
if self.zero_terminated {
|
||||
0
|
||||
} else {
|
||||
b'\n' as u8
|
||||
b'\n'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue