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 {
|
fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let delim = match opts.opt_str("output-delimiter") {
|
let delim = match opts.opt_str("output-delimiter") {
|
||||||
Some(d) => d.clone(),
|
Some(d) => d,
|
||||||
None => "\t".to_owned(),
|
None => "\t".to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -764,7 +764,7 @@ fn preserve_hardlinks(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !(*found_hard_link) && nlinks > 1 {
|
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",
|
"a value 2 characters or longer",
|
||||||
"--delimiter",
|
"--delimiter",
|
||||||
"-d"
|
"-d"
|
||||||
).to_owned())
|
))
|
||||||
} else {
|
} else {
|
||||||
let delim = if delim.is_empty() {
|
let delim = if delim.is_empty() {
|
||||||
"\0".to_owned()
|
"\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(
|
(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)")
|
msg_expects_no_more_than_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)"),
|
||||||
.to_owned(),
|
|
||||||
),
|
),
|
||||||
_ => 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 {
|
let mode_parse = match mode_parse {
|
||||||
Err(_) => mode_parse,
|
Err(_) => mode_parse,
|
||||||
Ok(mode) => match mode {
|
Ok(mode) => match mode {
|
||||||
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("delimiter") => Err(
|
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("delimiter") => Err(
|
||||||
msg_opt_only_usable_if!("printing a sequence of fields", "--delimiter", "-d")
|
msg_opt_only_usable_if!("printing a sequence of fields", "--delimiter", "-d"),
|
||||||
.to_owned(),
|
|
||||||
),
|
),
|
||||||
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("only-delimited") => {
|
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("only-delimited") => {
|
||||||
Err(msg_opt_only_usable_if!(
|
Err(msg_opt_only_usable_if!(
|
||||||
"printing a sequence of fields",
|
"printing a sequence of fields",
|
||||||
"--only-delimited",
|
"--only-delimited",
|
||||||
"-s"
|
"-s"
|
||||||
).to_owned())
|
))
|
||||||
}
|
}
|
||||||
_ => Ok(mode),
|
_ => Ok(mode),
|
||||||
},
|
},
|
||||||
|
|
|
@ -224,7 +224,7 @@ impl OdOptions {
|
||||||
let formats = match parse_format_flags(&args) {
|
let formats = match parse_format_flags(&args) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
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();
|
let i = it.next();
|
||||||
match i {
|
match i {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
new_amount = ((u.clone() as u16) * fact) + carry;
|
new_amount = ((*u as u16) * fact) + carry;
|
||||||
rem = new_amount % base;
|
rem = new_amount % base;
|
||||||
carry = (new_amount - rem) / base;
|
carry = (new_amount - rem) / base;
|
||||||
ret_rev.push(rem as u8)
|
ret_rev.push(rem as u8)
|
||||||
|
@ -64,9 +64,9 @@ pub fn arrnum_int_div_step<'a>(
|
||||||
let mut it_f = refd_vals.iter();
|
let mut it_f = refd_vals.iter();
|
||||||
loop {
|
loop {
|
||||||
let u = match it_replace.next() {
|
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() {
|
None => match it_f.next() {
|
||||||
Some(u_orig) => u_orig.clone() as u16,
|
Some(u_orig) => *u_orig as u16,
|
||||||
None => {
|
None => {
|
||||||
if !after_decimal {
|
if !after_decimal {
|
||||||
break;
|
break;
|
||||||
|
@ -176,7 +176,7 @@ pub fn arrnum_int_add(arrnum: &[u8], basenum: u8, base_ten_int_term: u8) -> Vec<
|
||||||
let i = it.next();
|
let i = it.next();
|
||||||
match i {
|
match i {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
new_amount = (u.clone() as u16) + carry;
|
new_amount = (*u as u16) + carry;
|
||||||
rem = new_amount % base;
|
rem = new_amount % base;
|
||||||
carry = (new_amount - rem) / base;
|
carry = (new_amount - rem) / base;
|
||||||
ret_rev.push(rem as u8)
|
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
|
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();
|
let mut result: Vec<u8> = Vec::new();
|
||||||
result.push(0);
|
result.push(0);
|
||||||
for i in src {
|
for i in src {
|
||||||
result = arrnum_int_mult(&result, radix_dest, radix_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
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unsigned_to_arrnum(src: u16) -> Vec<u8> {
|
pub fn unsigned_to_arrnum(src: u16) -> Vec<u8> {
|
||||||
let mut result: Vec<u8> = Vec::new();
|
let mut result: Vec<u8> = Vec::new();
|
||||||
let mut src_tmp: u16 = src.clone();
|
let mut src_tmp: u16 = src;
|
||||||
while src_tmp > 0 {
|
while src_tmp > 0 {
|
||||||
result.push((src_tmp % 10) as u8);
|
result.push((src_tmp % 10) as u8);
|
||||||
src_tmp /= 10;
|
src_tmp /= 10;
|
||||||
|
@ -235,7 +235,7 @@ pub fn base_conv_float(src: &[u8], radix_src: u8, radix_dest: u8) -> f64 {
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
factor /= radix_src_float;
|
factor /= radix_src_float;
|
||||||
r += factor * (u.clone() as f64)
|
r += factor * (*u as f64)
|
||||||
}
|
}
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn get_inprefix(str_in: &str, field_type: &FieldType) -> InPrefix {
|
||||||
sign: 1,
|
sign: 1,
|
||||||
offset: 0,
|
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
|
// skip spaces and ensure topchar is the first non-space char
|
||||||
// (or None if none exists)
|
// (or None if none exists)
|
||||||
loop {
|
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
|
// if it is a numeric field, passing the field details
|
||||||
// and an iterator to the argument
|
// and an iterator to the argument
|
||||||
pub fn num_format(field: &FormatField, in_str_opt: Option<&String>) -> Option<String> {
|
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
|
// num format mainly operates by further delegating to one of
|
||||||
// several Formatter structs depending on the field
|
// several Formatter structs depending on the field
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue