Skip to content

Commit 909e4d8

Browse files
committed
Streamline package selection predicate
This groups package selection logic in one place, reducing the need for boxing the resulting closure and making it easier to reason locally about the package selection.
1 parent 641ef6b commit 909e4d8

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/cli.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub struct Opt {
349349
pub cmd: Command,
350350
}
351351

352-
fn make_pkg_predicate(ws: &Workspace<'_>, args: PackageSelectOptions) -> Result<Box<dyn Fn(&Package) -> bool>, String> {
352+
fn make_pkg_predicate(ws: &Workspace<'_>, args: PackageSelectOptions) -> Result<impl Fn(&Package) -> bool, String> {
353353
let PackageSelectOptions {
354354
packages,
355355
skip,
@@ -408,18 +408,17 @@ fn make_pkg_predicate(ws: &Workspace<'_>, args: PackageSelectOptions) -> Result<
408408
value
409409
};
410410

411-
if !packages.is_empty() {
412-
trace!("going for matching against {:?}", packages);
413-
return Ok(Box::new(move |p: &Package| {
414-
publish(p) && packages.contains(&p.name())
415-
}));
416-
}
411+
Ok(move |p: &Package| {
412+
if !publish(p) {
413+
return false;
414+
}
417415

418-
if !skip.is_empty() || !ignore_pre_version.is_empty() {
419-
return Ok(Box::new(move |p: &Package| {
420-
if !publish(p) {
421-
return false;
422-
}
416+
if !packages.is_empty() {
417+
trace!("going for matching against {:?}", packages);
418+
return packages.contains(&p.name());
419+
}
420+
421+
if !skip.is_empty() || !ignore_pre_version.is_empty() {
423422
let name = p.name();
424423
if skip.iter().any(|r| r.is_match(&name)) {
425424
return false;
@@ -431,11 +430,10 @@ fn make_pkg_predicate(ws: &Workspace<'_>, args: PackageSelectOptions) -> Result<
431430
}
432431
}
433432
}
434-
true
435-
}));
436-
}
433+
}
437434

438-
Ok(Box::new(publish))
435+
true
436+
})
439437
}
440438

441439
fn verify_readme_feature() -> Result<(), String> {

0 commit comments

Comments
 (0)