This revision was automatically updated to reflect the committed changes.
Closed by commit rHG3bf6979a1785: rust-cpython: generalised conversion function 
(authored by gracinet, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5549?vs=13127&id=13173

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