Skip to content

Commit

Permalink
apply select pedantic clippy recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Apr 1, 2022
1 parent 916f5cb commit 3fb3905
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
if args.flag_no_headers {
return fail!("dynfmt operation requires headers.");
} else {
safe_headers = util::safe_header_names(headers, false);
safe_headers = util::safe_header_names(&headers, false);
let formatstr_re: &'static Regex = regex!(r"\{(?P<key>\w+)?\}");
for format_fields in formatstr_re.captures_iter(&args.flag_formatstr) {
dynfmt_fields.push(format_fields.name("key").unwrap().as_str());
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Args {

let mut iters = rdrs
.iter_mut()
.map(|rdr| rdr.byte_records())
.map(csv::Reader::byte_records)
.collect::<Vec<_>>();
'OUTER: loop {
let mut record = csv::ByteRecord::new();
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ where
{
xs.next()
.and_then(|bytes| from_utf8(bytes).ok())
.map(|s| s.to_lowercase())
.map(str::to_lowercase)
}
8 changes: 4 additions & 4 deletions src/cmd/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<R: io::Read + io::Seek> ValueIndex<R> {
row_idx.write_u64::<BigEndian>(row.position().unwrap().byte())?;

let fields: Vec<_> = sel.select(&row).map(|v| transform(v, casei)).collect();
if !fields.iter().any(|f| f.is_empty()) {
if !fields.iter().any(std::vec::Vec::is_empty) {
match val_idx.entry(fields) {
Entry::Vacant(v) => {
let mut rows = Vec::with_capacity(4);
Expand Down Expand Up @@ -234,13 +234,13 @@ impl<R> fmt::Debug for ValueIndex<R> {
// Sort the values by order of first appearance.
let mut kvs = self.values.iter().collect::<Vec<_>>();
kvs.sort_by(|&(_, v1), &(_, v2)| v1[0].cmp(&v2[0]));
for (keys, rows) in kvs.into_iter() {
for (keys, rows) in kvs {
// This is just for debugging, so assume Unicode for now.
let keys = keys
.iter()
.map(|k| String::from_utf8(k.to_vec()).unwrap())
.map(|k| String::from_utf8(k.clone()).unwrap())
.collect::<Vec<_>>();
writeln!(f, "({}) => {:?}", keys.join(", "), rows)?
writeln!(f, "({}) => {:?}", keys.join(", "), rows)?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl GroupMemorizer for GroupValues {
self.default
.clone()
.or_else(|| self.map.get(&col).cloned())
.unwrap_or_else(|| field.to_vec())
.unwrap_or_else(|| field.clone())
} else {
field
},
Expand Down
11 changes: 6 additions & 5 deletions src/cmd/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
wtr.write_record(vec!["field", "value", "count"])?;
let head_ftables = headers.into_iter().zip(tables.into_iter());
for (i, (header, ftab)) in head_ftables.enumerate() {
let mut header = header.to_vec();
if rconfig.no_headers {
header = (i + 1).to_string().into_bytes();
}
for (value, count) in args.counts(&ftab).into_iter() {
let header = if rconfig.no_headers {
(i + 1).to_string().into_bytes()
} else {
header.to_vec()
};
for (value, count) in args.counts(&ftab) {
let count = count.to_string();
let row = vec![&*header, &*value, count.as_bytes()];
wtr.write_record(row)?;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {

let num_inputs = configs.len();
let mut headers: Vec<Vec<u8>> = vec![];
for conf in configs.into_iter() {
for conf in configs {
let mut rdr = conf.reader()?;
for header in rdr.byte_headers()?.iter() {
if !args.flag_intersect || !headers.iter().any(|h| &**h == header) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/jsonl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn json_line_to_csv_record(value: &Value, headers: &[Vec<String>]) -> csv::Strin
Value::String(v) => v,
Value::Array(v) => v
.iter()
.map(|x| x.to_string())
.map(std::string::ToString::to_string)
.collect::<Vec<_>>()
.join(","),
_ => String::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {

let mut wtr = Config::new(&args.flag_output).writer()?;
rconfig.write_headers(&mut rdr, &mut wtr)?;
for r in all.into_iter() {
for r in all {
wtr.write_byte_record(&r)?;
}
Ok(wtr.flush()?)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
sample_reservoir(&mut rdr, sample_size as u64, args.flag_seed)?
}
};
for row in sampled.into_iter() {
for row in sampled {
wtr.write_byte_record(&row)?;
}
Ok(wtr.flush()?)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/searchset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let matched = pattern.is_match(f);
if matched && do_match_list {
let mut matches: Vec<_> = pattern.matches(f).into_iter().collect();
for j in matches.iter_mut() {
for j in &mut matches {
*j += 1; // so the list is human readable - i.e. not zero-based
}
match_list = format!("{:?}", matches);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let mut wtr = Config::new(&args.flag_output).writer()?;
let mut prev: Option<csv::ByteRecord> = None;
rconfig.write_headers(&mut rdr, &mut wtr)?;
for r in all.into_iter() {
for r in all {
if args.flag_uniq {
match prev {
Some(other_r) => match iter_cmp(sel.select(&r), sel.select(&other_r)) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Args {
for i in 0..nrows {
let mut record = ByteRecord::new();

for row in all.iter() {
for row in &all {
record.push_field(&row[i]);
}
wtr.write_byte_record(&record)?;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ fn write_error_report(input_path: &str, validation_error_messages: Vec<String>)

let mut output_writer = BufWriter::with_capacity(wtr_buffer_size, output_file);

output_writer.write_all("row_number\tfield\terror\n".as_bytes())?;
output_writer.write_all(b"row_number\tfield\terror\n")?;

// write out error report
for error_msg in validation_error_messages {
Expand Down

0 comments on commit 3fb3905

Please sign in to comment.