# HG changeset patch # User Georges Racinet # Date 1547051496 -3600 # Node ID 3bf6979a1785d9af70c02f15327f188f7c1acdb5 # Parent 1b4b94bac8a0224931fe8b8e67a7c9b08798f33d rust-cpython: generalised conversion function Because `hg::ancestors::MissingAncestors` has methods taking some `HashSet` besides `impl IntoIterator` as parameters we'll need the more generic `rev_pyiter_collect()` function to also build these Differential Revision: https://phab.mercurial-scm.org/D5549 diff -r 1b4b94bac8a0 -r 3bf6979a1785 rust/hg-cpython/src/ancestors.rs --- a/rust/hg-cpython/src/ancestors.rs Tue Jan 08 14:00:33 2019 +0100 +++ b/rust/hg-cpython/src/ancestors.rs Wed Jan 09 17:31:36 2019 +0100 @@ -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)