diff --git a/src/config/fields/field_selection.rs b/src/config/fields/field_selection.rs index 7860e29..f80466a 100644 --- a/src/config/fields/field_selection.rs +++ b/src/config/fields/field_selection.rs @@ -19,7 +19,7 @@ impl FromStr for FieldSelections { type Err = Error; fn from_str(s: &str) -> Result { let ranges = s - .split(",") + .split(',') .map(|s| { let field: FieldSelection = s.parse()?; let range: RangeInclusive = field.into(); @@ -52,13 +52,13 @@ impl FieldSelections { impl FromStr for FieldSelection { type Err = Error; fn from_str(s: &str) -> Result { - let (start, end) = match s.split('-').collect::>().as_slice() { - &[x] => { + let (start, end) = match *s.splitn(2, '-').collect::>().as_slice() { + [x] => { let x_parsed = x.parse::()?; (x_parsed, Some(x_parsed)) } - &[x, ""] => (x.parse::()?, None), - &[x, y] => (x.parse::()?, Some(y.parse::()?)), + [x, ""] => (x.parse::()?, None), + [x, y] => (x.parse::()?, Some(y.parse::()?)), _ => bail!( "Failed to parse \"{}\" as field selection, expected format is a|a-b|a-", s diff --git a/src/config/fields/mod.rs b/src/config/fields/mod.rs index e2a6934..fb8ce5b 100644 --- a/src/config/fields/mod.rs +++ b/src/config/fields/mod.rs @@ -52,8 +52,9 @@ impl TableFormatter for &str { line.split(separator) .enumerate() // TODO: seems inefficient, try applying selection to whole line at a time - .filter(|(idx, _)| selections.contains(*idx)) - .map(|(_, field)| field) + .filter_map(|(idx, field)| { + selections.contains(idx).then_some(field) + }) .join("\t") }) .join("\n"),