gracinet created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Because `hg::ancestors::MissingAncestors` has methods taking
  some `HashSet<Revision>` besides `impl IntoIterator<Item = Revision>`
  as parameters we'll need the more generic `rev_pyiter_collect()` function
  to also build these

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5549

AFFECTED FILES
  rust/hg-cpython/src/ancestors.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/ancestors.rs b/rust/hg-cpython/src/ancestors.rs
--- a/rust/hg-cpython/src/ancestors.rs
+++ b/rust/hg-cpython/src/ancestors.rs
@@ -30,13 +30,18 @@
 use hg::Revision;
 use hg::{AncestorsIterator as CoreIterator, LazyAncestors as CoreLazy};
 use std::cell::RefCell;
+use std::iter::FromIterator;
 
-/// Utility function to convert a Python iterable into a Vec<Revision>
+/// Utility function to convert a Python iterable into various collections
 ///
-/// We need this to feed to `AncestorIterators` constructors because
-/// a `PyErr` can arise at each step of iteration, whereas our inner objects
+/// We need this in particular to feed to various methods of inner objects
+/// with `impl IntoIterator<Item=Revision>` arguments, because
+/// a `PyErr` can arise at each step of iteration, whereas these methods
 /// expect iterables over `Revision`, not over some `Result<Revision, PyErr>`
-fn reviter_to_revvec(py: Python, revs: PyObject) -> PyResult<Vec<Revision>> {
+fn rev_pyiter_collect<C>(py: Python, revs: &PyObject) -> PyResult<C>
+where
+    C: FromIterator<Revision>,
+{
     revs.iter(py)?
         .map(|r| r.and_then(|o| o.extract::<Revision>(py)))
         .collect()
@@ -64,7 +69,7 @@
 
     def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision,
                 inclusive: bool) -> PyResult<AncestorsIterator> {
-        let initvec = reviter_to_revvec(py, initrevs)?;
+        let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
         let ait = CoreIterator::new(
             Index::new(py, index)?,
             initvec,
@@ -103,7 +108,7 @@
 
     def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision,
                 inclusive: bool) -> PyResult<Self> {
-        let initvec = reviter_to_revvec(py, initrevs)?;
+        let initvec: Vec<Revision> = rev_pyiter_collect(py, &initrevs)?;
 
         let lazy =
             CoreLazy::new(Index::new(py, index)?, initvec, stoprev, inclusive)



To: gracinet, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to