From f3045ad5a4496a44d1b4f21b5be38403396d7a7d Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 12 Feb 2025 20:12:27 +0200 Subject: [PATCH] update `limit` argument data type --- src/argument.rs | 4 ++-- src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/argument.rs b/src/argument.rs index 2d3b7a7..e784778 100644 --- a/src/argument.rs +++ b/src/argument.rs @@ -8,8 +8,8 @@ pub struct Argument { pub index: Option, /// Limit channel items (unlimited by default) - #[arg(short, long, default_value_t = 0)] - pub limit: usize, + #[arg(short, long)] + pub limit: Option, /// Show output (`dw` by default) #[arg(short, long, default_value_t = String::from("dw"))] diff --git a/src/main.rs b/src/main.rs index a32799a..b3489d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { .items() .iter() { - if argument.limit > 0 && total >= argument.limit { + if argument.limit.is_some_and(|limit| total >= limit) { break; } @@ -108,7 +108,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { let mut files: Vec<_> = read_dir(&path)?.filter_map(Result::ok).collect(); files.sort_by_key(|f| f.file_name()); - let mut data = Vec::with_capacity(argument.limit); + let mut data = Vec::with_capacity(argument.limit.unwrap_or_default()); let mut index = File::create(&index_filename)?; let mut total = 0;