Skip to content

Commit eede6bc

Browse files
authored
Collection of formatting & other minor improvements (oberblastmeister#25)
* run rustfmt * box AhoCoresick structs when in enums with small variants * prefer `impl From<>` to `impl Into<>` * remove unnecessary lifetime parameter * remove unnecessary clone() * put format! macro into a closure for faster successful test running * remove unnecessary refs and consuming iterators * add allow(clippy) annotation & comment due to false positive * merge imports from same source
1 parent 8a48c05 commit eede6bc

File tree

8 files changed

+16
-18
lines changed

8 files changed

+16
-18
lines changed

src/app/command/empty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub struct Args {
2525
/// This can be useful in scripts.
2626
#[clap(short, long)]
2727
force: bool,
28-
2928
}
3029

3130
impl Args {

src/app/command/list.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Args {
2626
impl Args {
2727
pub fn run(&self, config_args: &app::ConfigArgs) -> Result<()> {
2828
let items = self.query_args.list(false)?;
29-
display_items((&items).into_iter(), config_args)?;
29+
display_items(items.iter(), config_args)?;
3030
Ok(())
3131
}
3232
}
@@ -93,7 +93,7 @@ impl QueryArgs {
9393
}
9494
new_items.extend(
9595
items[range.to_std()]
96-
.into_iter()
96+
.iter()
9797
.map(utils::clone_trash_item)
9898
.zip(range.into_iter())
9999
.map(swap),
@@ -150,8 +150,10 @@ pub fn indexed_items_to_table<'a>(
150150
base: &Path,
151151
) -> Result<Table> {
152152
let mut failed = 0;
153+
//this isn't actually needless since we need to reverse the items, which can't be done with a single-ended iterator
154+
#[allow(clippy::needless_collect)]
153155
let items: Vec<_> = items
154-
.filter_map(|(i, item)| match display_item(&item, use_color, base) {
156+
.filter_map(|(i, item)| match display_item(item, use_color, base) {
155157
Ok(s) => Some((i, s)),
156158
Err(_) => {
157159
failed += 1;
@@ -180,8 +182,7 @@ pub fn indexed_items_to_table<'a>(
180182
}
181183

182184
pub fn display_item(item: &TrashItem, color: bool, base: &Path) -> Result<(String, String)> {
183-
let mut displayed_path =
184-
utils::path::display(&item.original_path().strip_prefix(base).unwrap());
185+
let mut displayed_path = utils::path::display(item.original_path().strip_prefix(base).unwrap());
185186
if cfg!(target_os = "linux") && color {
186187
if let Some(style) = item_lscolors(item)? {
187188
let ansi_style = style.to_ansi_term_style();

src/app/command/restore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn restore_with_prompt(items: MaybeIndexedTrashItems, config_args: &app::ConfigA
5858
Ok(())
5959
}
6060

61-
fn restore<'a>(items: MaybeIndexedTrashItems) -> Result<()> {
61+
fn restore(items: MaybeIndexedTrashItems) -> Result<()> {
6262
trash::os_limited::restore_all(items.items())?;
6363
Ok(())
6464
}

src/filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl FilterArgs {
6767
let within = parse_time(self.within.as_deref())?;
6868
let patterns = match self.r#match {
6969
Match::Regex => Patterns::Regex(RegexSet::new(&self.patterns)?),
70-
Match::Substring => Patterns::Substring(AhoCorasick::new(&self.patterns)),
70+
Match::Substring => Patterns::Substring(Box::new(AhoCorasick::new(&self.patterns))),
7171
Match::Glob => Patterns::Glob(new_globset(self.patterns.iter().map(|s| &**s))?),
7272
Match::Exact => Patterns::Exact(self.patterns.iter().cloned().collect()),
7373
};
@@ -134,7 +134,7 @@ impl TimeFilter {
134134

135135
pub enum Patterns {
136136
Regex(RegexSet),
137-
Substring(AhoCorasick),
137+
Substring(Box<AhoCorasick>),
138138
Glob(GlobSet),
139139
Exact(HashSet<String>),
140140
}

src/range_set.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ impl From<Vec<Range>> for RangeSet {
1919
}
2020
}
2121

22-
impl Into<Vec<Range>> for RangeSet {
23-
fn into(self) -> Vec<Range> {
24-
self.ranges
22+
impl From<RangeSet> for Vec<Range> {
23+
fn from(range_set: RangeSet) -> Self {
24+
range_set.ranges
2525
}
2626
}
2727

src/range_syntax.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ mod tests {
3838

3939
fn parse_succeed<const N: usize>(s: &str, expect: [ops::Range<u32>; N]) {
4040
assert_eq!(
41-
parse_range_set(s).expect(&format!("Failed to parse str `{}` into a restore index", s)),
41+
parse_range_set(s)
42+
.unwrap_or_else(|_| panic!("Failed to parse str `{}` into a restore index", s)),
4243
expect.into_iter().map(Into::into).collect()
4344
);
4445
}

src/table.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use prettytable::{cell, row, Cell, Row, Table};
77
use terminal_size::{terminal_size, Width};
88

99
use crate::border::Border;
10-
use crate::utils::{
11-
get_metadata, Pair,
12-
};
13-
use crate::utils::{date, path};
10+
use crate::utils::{date, get_metadata, path, Pair};
1411

1512
pub struct SizedTable {
1613
opt: Opt,

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn clone_trash_item(item: &TrashItem) -> TrashItem {
7171
id: item.id.clone(),
7272
name: item.name.clone(),
7373
original_parent: item.original_parent.clone(),
74-
time_deleted: item.time_deleted.clone(),
74+
time_deleted: item.time_deleted,
7575
}
7676
}
7777

0 commit comments

Comments
 (0)