aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/remove_command.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 20:20:15 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 20:20:15 +0900
commit1dfd1ae32b9b27573b9ee4439674091b792bcce0 (patch)
treed715462a35a4b5e59f828e2c18865a1b322e9abc /crates/shirabe/src/command/remove_command.rs
parentb6604e1395f003748fe40a44e1190470632a40ce (diff)
downloadphp-shirabe-1dfd1ae32b9b27573b9ee4439674091b792bcce0.tar.gz
php-shirabe-1dfd1ae32b9b27573b9ee4439674091b792bcce0.tar.zst
php-shirabe-1dfd1ae32b9b27573b9ee4439674091b792bcce0.zip
refactor(preg): make preg_grep() return an iterator
Callers had to build a temporary Vec<&str> at every call site to satisfy the &[&str] parameter. Taking IntoIterator and yielding the matched items lets them pass owned or borrowed strings directly. The flags variant and PREG_GREP_INVERT go away with it: no caller passes flags, and Composer's Preg::grep() has no such parameter either.
Diffstat (limited to 'crates/shirabe/src/command/remove_command.rs')
-rw-r--r--crates/shirabe/src/command/remove_command.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs
index a8b525e6..bba0285f 100644
--- a/crates/shirabe/src/command/remove_command.rs
+++ b/crates/shirabe/src/command/remove_command.rs
@@ -393,11 +393,11 @@ impl Command for RemoveCommand {
.and_then(|v| v.as_array())
.map(|m| m.keys().cloned().collect())
.unwrap_or_default();
- let type_keys_refs: Vec<&str> = type_keys.iter().map(|s| s.as_str()).collect();
- let matches_in_type = Preg::grep(
+ let matches_in_type: Vec<&String> = Preg::grep(
base_package::package_name_to_regexp(package),
- &type_keys_refs,
- );
+ type_keys.iter(),
+ )
+ .collect();
let alt_type_keys: Vec<String> = composer_data
.as_array()
@@ -405,15 +405,14 @@ impl Command for RemoveCommand {
.and_then(|v| v.as_array())
.map(|m| m.keys().cloned().collect())
.unwrap_or_default();
- let alt_type_keys_refs: Vec<&str> =
- alt_type_keys.iter().map(|s| s.as_str()).collect();
- let matches_in_alt_type = Preg::grep(
+ let matches_in_alt_type: Vec<&String> = Preg::grep(
base_package::package_name_to_regexp(package),
- &alt_type_keys_refs,
- );
+ alt_type_keys.iter(),
+ )
+ .collect();
if !type_keys.is_empty() && !matches_in_type.is_empty() {
- for matched_package in &matches_in_type {
+ for matched_package in matches_in_type {
if dry_run {
to_remove
.entry(r#type.to_string())
@@ -424,7 +423,7 @@ impl Command for RemoveCommand {
}
}
} else if !alt_type_keys.is_empty() && !matches_in_alt_type.is_empty() {
- for matched_package in &matches_in_alt_type {
+ for matched_package in matches_in_alt_type {
io.write_error(&format!(
"<warning>{} could not be found in {} but it is present in {}</warning>",
matched_package, r#type, alt_type