From 9140e5b686f19eab6ef913bc005337fbd4b6db03 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 7 Jul 2023 19:40:07 +0900 Subject: [PATCH] conflicts: relax from_legacy_form() to accept any iterable This will help to rewrite refs::merge_ref_targets() to leverage Conflict type. I'm not pretty sure if we'll want to do that, but this change seems also good for the existing code. --- lib/src/conflicts.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index ee7375d89..c1b29362b 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -54,7 +54,10 @@ impl Conflict { /// Create a `Conflict` from a `removes` and `adds`, padding with `None` to /// make sure that there is exactly one more `adds` than `removes`. - pub fn from_legacy_form(removes: Vec, adds: Vec) -> Conflict> { + pub fn from_legacy_form( + removes: impl IntoIterator, + adds: impl IntoIterator, + ) -> Conflict> { let mut removes = removes.into_iter().map(Some).collect_vec(); let mut adds = adds.into_iter().map(Some).collect_vec(); while removes.len() + 1 < adds.len() { @@ -196,12 +199,8 @@ impl Conflict> { /// Create a `Conflict` from a `backend::Conflict`, padding with `None` to /// make sure that there is exactly one more `adds()` than `removes()`. pub fn from_backend_conflict(conflict: backend::Conflict) -> Self { - let removes = conflict - .removes - .into_iter() - .map(|term| term.value) - .collect(); - let adds = conflict.adds.into_iter().map(|term| term.value).collect(); + let removes = conflict.removes.into_iter().map(|term| term.value); + let adds = conflict.adds.into_iter().map(|term| term.value); Conflict::from_legacy_form(removes, adds) }