mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (redundant clone)
This commit is contained in:
parent
2e90c78fae
commit
564168ccfc
6 changed files with 18 additions and 20 deletions
|
@ -26,7 +26,7 @@ static LONG_HELP: &str = "";
|
|||
fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
|
||||
let mut s = String::new();
|
||||
let delim = match opts.opt_str("output-delimiter") {
|
||||
Some(d) => d.clone(),
|
||||
Some(d) => d,
|
||||
None => "\t".to_owned(),
|
||||
};
|
||||
|
||||
|
|
|
@ -764,7 +764,7 @@ fn preserve_hardlinks(
|
|||
}
|
||||
}
|
||||
if !(*found_hard_link) && nlinks > 1 {
|
||||
hard_links.push((dest.clone().to_str().unwrap().to_string(), inode));
|
||||
hard_links.push((dest.to_str().unwrap().to_string(), inode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -488,7 +488,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
"a value 2 characters or longer",
|
||||
"--delimiter",
|
||||
"-d"
|
||||
).to_owned())
|
||||
))
|
||||
} else {
|
||||
let delim = if delim.is_empty() {
|
||||
"\0".to_owned()
|
||||
|
@ -519,25 +519,23 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
}
|
||||
}),
|
||||
(ref b, ref c, ref f) if b.is_some() || c.is_some() || f.is_some() => Err(
|
||||
msg_expects_no_more_than_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)")
|
||||
.to_owned(),
|
||||
msg_expects_no_more_than_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)"),
|
||||
),
|
||||
_ => Err(msg_expects_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)").to_owned()),
|
||||
_ => Err(msg_expects_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)")),
|
||||
};
|
||||
|
||||
let mode_parse = match mode_parse {
|
||||
Err(_) => mode_parse,
|
||||
Ok(mode) => match mode {
|
||||
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("delimiter") => Err(
|
||||
msg_opt_only_usable_if!("printing a sequence of fields", "--delimiter", "-d")
|
||||
.to_owned(),
|
||||
msg_opt_only_usable_if!("printing a sequence of fields", "--delimiter", "-d"),
|
||||
),
|
||||
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("only-delimited") => {
|
||||
Err(msg_opt_only_usable_if!(
|
||||
"printing a sequence of fields",
|
||||
"--only-delimited",
|
||||
"-s"
|
||||
).to_owned())
|
||||
))
|
||||
}
|
||||
_ => Ok(mode),
|
||||
},
|
||||
|
|
|
@ -224,7 +224,7 @@ impl OdOptions {
|
|||
let formats = match parse_format_flags(&args) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
return Err(e.to_string());
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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.clone() as u16) * fact) + carry;
|
||||
new_amount = ((*u as u16) * fact) + carry;
|
||||
rem = new_amount % base;
|
||||
carry = (new_amount - rem) / base;
|
||||
ret_rev.push(rem as u8)
|
||||
|
@ -64,9 +64,9 @@ pub fn arrnum_int_div_step<'a>(
|
|||
let mut it_f = refd_vals.iter();
|
||||
loop {
|
||||
let u = match it_replace.next() {
|
||||
Some(u_rep) => u_rep.clone() as u16,
|
||||
Some(u_rep) => *u_rep as u16,
|
||||
None => match it_f.next() {
|
||||
Some(u_orig) => u_orig.clone() as u16,
|
||||
Some(u_orig) => *u_orig as u16,
|
||||
None => {
|
||||
if !after_decimal {
|
||||
break;
|
||||
|
@ -176,7 +176,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.clone() as u16) + carry;
|
||||
new_amount = (*u as u16) + carry;
|
||||
rem = new_amount % base;
|
||||
carry = (new_amount - rem) / base;
|
||||
ret_rev.push(rem as u8)
|
||||
|
@ -195,19 +195,19 @@ pub fn arrnum_int_add(arrnum: &[u8], basenum: u8, base_ten_int_term: u8) -> Vec<
|
|||
ret
|
||||
}
|
||||
|
||||
pub fn base_conv_vec(src: &Vec<u8>, radix_src: u8, radix_dest: u8) -> Vec<u8> {
|
||||
pub fn base_conv_vec(src: &[u8], radix_src: u8, radix_dest: u8) -> Vec<u8> {
|
||||
let mut result: Vec<u8> = Vec::new();
|
||||
result.push(0);
|
||||
for i in src {
|
||||
result = arrnum_int_mult(&result, radix_dest, radix_src);
|
||||
result = arrnum_int_add(&result, radix_dest, i.clone());
|
||||
result = arrnum_int_add(&result, radix_dest, *i);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn unsigned_to_arrnum(src: u16) -> Vec<u8> {
|
||||
let mut result: Vec<u8> = Vec::new();
|
||||
let mut src_tmp: u16 = src.clone();
|
||||
let mut src_tmp: u16 = src;
|
||||
while src_tmp > 0 {
|
||||
result.push((src_tmp % 10) as u8);
|
||||
src_tmp /= 10;
|
||||
|
@ -235,7 +235,7 @@ pub fn base_conv_float(src: &[u8], radix_src: u8, radix_dest: u8) -> f64 {
|
|||
}
|
||||
i += 1;
|
||||
factor /= radix_src_float;
|
||||
r += factor * (u.clone() as f64)
|
||||
r += factor * (*u as f64)
|
||||
}
|
||||
r
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ fn get_inprefix(str_in: &str, field_type: &FieldType) -> InPrefix {
|
|||
sign: 1,
|
||||
offset: 0,
|
||||
};
|
||||
let mut topchar = str_it.next().clone();
|
||||
let mut topchar = str_it.next();
|
||||
// skip spaces and ensure topchar is the first non-space char
|
||||
// (or None if none exists)
|
||||
loop {
|
||||
|
@ -203,7 +203,7 @@ fn get_inprefix(str_in: &str, field_type: &FieldType) -> InPrefix {
|
|||
// if it is a numeric field, passing the field details
|
||||
// and an iterator to the argument
|
||||
pub fn num_format(field: &FormatField, in_str_opt: Option<&String>) -> Option<String> {
|
||||
let fchar = field.field_char.clone();
|
||||
let fchar = field.field_char;
|
||||
|
||||
// num format mainly operates by further delegating to one of
|
||||
// several Formatter structs depending on the field
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue