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 +/// 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` arguments, because +/// a `PyErr` can arise at each step of iteration, whereas these methods /// expect iterables over `Revision`, not over some `Result` -fn reviter_to_revvec(py: Python, revs: PyObject) -> PyResult> { +fn rev_pyiter_collect(py: Python, revs: &PyObject) -> PyResult +where + C: FromIterator, +{ revs.iter(py)? .map(|r| r.and_then(|o| o.extract::(py))) .collect() @@ -64,7 +69,7 @@ def __new__(_cls, index: PyObject, initrevs: PyObject, stoprev: Revision, inclusive: bool) -> PyResult { - let initvec = reviter_to_revvec(py, initrevs)?; + let initvec: Vec = 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 { - let initvec = reviter_to_revvec(py, initrevs)?; + let initvec: Vec = rev_pyiter_collect(py, &initrevs)?; let lazy = CoreLazy::new(Index::new(py, index)?, initvec, stoprev, inclusive)