refactor/polish ~ fix cargo clippy complaints (DRY struct def)

This commit is contained in:
Roy Ivy III 2019-12-26 15:08:10 -06:00
parent ea8ed8d5da
commit fa8540cb15
26 changed files with 90 additions and 90 deletions

View file

@ -339,7 +339,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
}; };
let convert_size_fn = { let convert_size_fn = {
if matches.opt_present("human-readable") || matches.opt_present("si") { if matches.opt_present("human-readable") || matches.opt_present("si") {
convert_size_human convert_size_human
} else if matches.opt_present("b") { } else if matches.opt_present("b") {
convert_size_b convert_size_b
} else if matches.opt_present("k") { } else if matches.opt_present("k") {

View file

@ -68,9 +68,9 @@ impl ASTNode {
fn new_node(token_idx: usize, op_type: &str, operands: OperandsList) -> Box<ASTNode> { fn new_node(token_idx: usize, op_type: &str, operands: OperandsList) -> Box<ASTNode> {
Box::new(ASTNode::Node { Box::new(ASTNode::Node {
token_idx: token_idx, token_idx,
op_type: op_type.into(), op_type: op_type.into(),
operands: operands, operands,
}) })
} }
fn new_leaf(token_idx: usize, value: &str) -> Box<ASTNode> { fn new_leaf(token_idx: usize, value: &str) -> Box<ASTNode> {

View file

@ -244,8 +244,8 @@ fn behaviour(matches: &getopts::Matches) -> Result<Behaviour, i32> {
}; };
Ok(Behaviour { Ok(Behaviour {
main_function: main_function, main_function,
specified_mode: specified_mode, specified_mode,
suffix: backup_suffix, suffix: backup_suffix,
verbose: matches.opt_present("v"), verbose: matches.opt_present("v"),
}) })

View file

@ -260,9 +260,9 @@ impl<'a> State<'a> {
}; };
State { State {
key: key, key,
file_name: name, file_name: name,
file_num: file_num, file_num,
print_unpaired: print_unpaired == file_num, print_unpaired: print_unpaired == file_num,
lines: f.lines(), lines: f.lines(),
seq: Vec::new(), seq: Vec::new(),

View file

@ -697,7 +697,7 @@ fn display_file_name(
Cell { Cell {
contents: name, contents: name,
width: width, width,
} }
} }

View file

@ -251,9 +251,9 @@ fn parse_options(args: &Matches) -> Result<NumfmtOptions> {
}?; }?;
Ok(NumfmtOptions { Ok(NumfmtOptions {
transform: transform, transform,
padding: padding, padding,
header: header, header,
}) })
} }

View file

@ -43,12 +43,12 @@ impl<'a, I> InputDecoder<'a, I> {
} // fast but uninitialized } // fast but uninitialized
InputDecoder { InputDecoder {
input: input, input,
data: bytes, data: bytes,
reserved_peek_length: peek_length, reserved_peek_length: peek_length,
used_normal_length: 0, used_normal_length: 0,
used_peek_length: 0, used_peek_length: 0,
byte_order: byte_order, byte_order,
} }
} }
} }

View file

@ -21,9 +21,9 @@ impl InputOffset {
/// creates a new `InputOffset` using the provided values. /// creates a new `InputOffset` using the provided values.
pub fn new(radix: Radix, byte_pos: usize, label: Option<usize>) -> InputOffset { pub fn new(radix: Radix, byte_pos: usize, label: Option<usize>) -> InputOffset {
InputOffset { InputOffset {
radix: radix, radix,
byte_pos: byte_pos, byte_pos,
label: label, label,
} }
} }

View file

@ -276,15 +276,15 @@ impl OdOptions {
}; };
Ok(OdOptions { Ok(OdOptions {
byte_order: byte_order, byte_order,
skip_bytes: skip_bytes, skip_bytes,
read_bytes: read_bytes, read_bytes,
label: label, label,
input_strings: input_strings, input_strings,
formats: formats, formats,
line_bytes: line_bytes, line_bytes,
output_duplicates: output_duplicates, output_duplicates,
radix: radix, radix,
}) })
} }
} }

View file

@ -69,11 +69,11 @@ impl OutputInfo {
OutputInfo { OutputInfo {
byte_size_line: line_bytes, byte_size_line: line_bytes,
print_width_line: print_width_line, print_width_line,
byte_size_block: byte_size_block, byte_size_block,
print_width_block: print_width_block, print_width_block,
spaced_formatters: spaced_formatters, spaced_formatters,
output_duplicates: output_duplicates, output_duplicates,
} }
} }

View file

@ -15,8 +15,8 @@ impl ParsedFormatterItemInfo {
add_ascii_dump: bool, add_ascii_dump: bool,
) -> ParsedFormatterItemInfo { ) -> ParsedFormatterItemInfo {
ParsedFormatterItemInfo { ParsedFormatterItemInfo {
formatter_item_info: formatter_item_info, formatter_item_info,
add_ascii_dump: add_ascii_dump, add_ascii_dump,
} }
} }
} }

View file

@ -177,7 +177,7 @@ mod tests {
fn new(inputs: Vec<&'a str>, option_names: Vec<&'a str>) -> MockOptions<'a> { fn new(inputs: Vec<&'a str>, option_names: Vec<&'a str>) -> MockOptions<'a> {
MockOptions { MockOptions {
inputs: inputs.iter().map(|s| s.to_string()).collect::<Vec<_>>(), inputs: inputs.iter().map(|s| s.to_string()).collect::<Vec<_>>(),
option_names: option_names, option_names,
} }
} }
} }

View file

@ -22,9 +22,9 @@ impl<R> PartialReader<R> {
/// to `None` if there should be no limit. /// to `None` if there should be no limit.
pub fn new(inner: R, skip: usize, limit: Option<usize>) -> Self { pub fn new(inner: R, skip: usize, limit: Option<usize>) -> Self {
PartialReader { PartialReader {
inner: inner, inner,
skip: skip, skip,
limit: limit, limit,
} }
} }
} }

View file

@ -41,7 +41,7 @@ impl<R> PeekReader<R> {
/// Create a new `PeekReader` wrapping `inner` /// Create a new `PeekReader` wrapping `inner`
pub fn new(inner: R) -> Self { pub fn new(inner: R) -> Self {
PeekReader { PeekReader {
inner: inner, inner,
temp_buffer: Vec::new(), temp_buffer: Vec::new(),
} }
} }

View file

@ -125,13 +125,13 @@ The utmp file will be {}",
} }
let pk = Pinky { let pk = Pinky {
include_idle: include_idle, include_idle,
include_heading: include_heading, include_heading,
include_fullname: include_fullname, include_fullname,
include_project: include_project, include_project,
include_plan: include_plan, include_plan,
include_home_and_shell: include_home_and_shell, include_home_and_shell,
include_where: include_where, include_where,
names: matches.free, names: matches.free,
}; };

View file

@ -96,7 +96,7 @@ pub fn arrnum_int_div_step<'a>(
} }
} }
DivOut { DivOut {
quotient: quotient, quotient,
remainder: rem_out, remainder: rem_out,
} }
} }

View file

@ -80,11 +80,11 @@ impl Sub {
} }
}; };
Sub { Sub {
min_width: min_width, min_width,
second_field: second_field, second_field,
field_char: field_char, field_char,
field_type: field_type, field_type,
orig: orig, orig,
} }
} }
} }

View file

@ -248,7 +248,7 @@ fn create_word_set(
word = word.to_lowercase(); word = word.to_lowercase();
} }
word_set.insert(WordRef { word_set.insert(WordRef {
word: word, word,
filename: file.clone(), filename: file.clone(),
global_line_nr: offs + count, global_line_nr: offs + count,
local_line_nr: count, local_line_nr: count,

View file

@ -109,7 +109,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
return 1; return 1;
} else { } else {
let options = Options { let options = Options {
force: force, force,
interactive: { interactive: {
if matches.opt_present("i") { if matches.opt_present("i") {
InteractiveMode::InteractiveAlways InteractiveMode::InteractiveAlways

View file

@ -76,7 +76,7 @@ impl FilenameGenerator {
indices.push(0); indices.push(0);
} }
FilenameGenerator { FilenameGenerator {
name_len: name_len, name_len,
nameset_indices: RefCell::new(indices), nameset_indices: RefCell::new(indices),
exhausted: Cell::new(false), exhausted: Cell::new(false),
} }
@ -137,12 +137,12 @@ impl<'a> BytesGenerator<'a> {
}; };
BytesGenerator { BytesGenerator {
total_bytes: total_bytes, total_bytes,
bytes_generated: Cell::new(0u64), bytes_generated: Cell::new(0u64),
block_size: BLOCK_SIZE, block_size: BLOCK_SIZE,
exact: exact, exact,
gen_type: gen_type, gen_type,
rng: rng, rng,
} }
} }
} }

View file

@ -106,14 +106,14 @@ impl<'a> FileMerger<'a> {
fn new(settings: &'a Settings) -> FileMerger<'a> { fn new(settings: &'a Settings) -> FileMerger<'a> {
FileMerger { FileMerger {
heap: BinaryHeap::new(), heap: BinaryHeap::new(),
settings: settings, settings,
} }
} }
fn push_file(&mut self, mut lines: Lines<BufReader<Box<dyn Read>>>) { fn push_file(&mut self, mut lines: Lines<BufReader<Box<dyn Read>>>) {
match lines.next() { match lines.next() {
Some(Ok(next_line)) => { Some(Ok(next_line)) => {
let mergeable_file = MergeableFile { let mergeable_file = MergeableFile {
lines: lines, lines,
current_line: next_line, current_line: next_line,
settings: &self.settings, settings: &self.settings,
}; };

View file

@ -396,9 +396,9 @@ impl Stater {
i = j; i = j;
tokens.push(Token::Directive { tokens.push(Token::Directive {
width: width, width,
flag: flag, flag,
precision: precision, precision,
format: chars[i], format: chars[i],
}) })
} }
@ -492,12 +492,12 @@ impl Stater {
Ok(Stater { Ok(Stater {
follow: matches.opt_present("dereference"), follow: matches.opt_present("dereference"),
showfs: showfs, showfs,
from_user: !fmtstr.is_empty(), from_user: !fmtstr.is_empty(),
files: matches.free, files: matches.free,
default_tokens: default_tokens, default_tokens,
default_dev_tokens: default_dev_tokens, default_dev_tokens,
mount_list: mount_list, mount_list,
}) })
} }

View file

@ -119,8 +119,8 @@ fn open(name: String, append: bool) -> Box<dyn Write> {
} }
}; };
Box::new(NamedWriter { Box::new(NamedWriter {
inner: inner, inner,
path: path, path,
}) as Box<dyn Write> }) as Box<dyn Write>
} }

View file

@ -45,7 +45,7 @@ impl DeleteOperation {
fn new(set: ExpandSet, complement: bool) -> DeleteOperation { fn new(set: ExpandSet, complement: bool) -> DeleteOperation {
DeleteOperation { DeleteOperation {
bset: set.map(|c| c as usize).collect(), bset: set.map(|c| c as usize).collect(),
complement: complement, complement,
} }
} }
} }
@ -70,7 +70,7 @@ impl SqueezeOperation {
fn new(squeeze_set: ExpandSet, complement: bool) -> SqueezeOperation { fn new(squeeze_set: ExpandSet, complement: bool) -> SqueezeOperation {
SqueezeOperation { SqueezeOperation {
squeeze_set: squeeze_set.map(|c| c as usize).collect(), squeeze_set: squeeze_set.map(|c| c as usize).collect(),
complement: complement, complement,
} }
} }
} }
@ -100,7 +100,7 @@ impl DeleteAndSqueezeOperation {
DeleteAndSqueezeOperation { DeleteAndSqueezeOperation {
delete_set: delete_set.map(|c| c as usize).collect(), delete_set: delete_set.map(|c| c as usize).collect(),
squeeze_set: squeeze_set.map(|c| c as usize).collect(), squeeze_set: squeeze_set.map(|c| c as usize).collect(),
complement: complement, complement,
} }
} }
} }

View file

@ -76,10 +76,10 @@ impl Options {
}; };
Options { Options {
files: files, files,
tabstops: tabstops, tabstops,
aflag: aflag, aflag,
uflag: uflag, uflag,
} }
} }
} }

View file

@ -204,21 +204,21 @@ pub fn uumain(args: Vec<String>) -> i32 {
} }
let mut who = Who { let mut who = Who {
do_lookup: do_lookup, do_lookup,
short_list: short_list, short_list,
short_output: short_output, short_output,
include_idle: include_idle, include_idle,
include_heading: include_heading, include_heading,
include_mesg: include_mesg, include_mesg,
include_exit: include_exit, include_exit,
need_boottime: need_boottime, need_boottime,
need_deadprocs: need_deadprocs, need_deadprocs,
need_login: need_login, need_login,
need_initspawn: need_initspawn, need_initspawn,
need_clockchange: need_clockchange, need_clockchange,
need_runlevel: need_runlevel, need_runlevel,
need_users: need_users, need_users,
my_line_only: my_line_only, my_line_only,
has_records: false, has_records: false,
args: matches.free, args: matches.free,
}; };