Patchwork [3,of,7] rust-cpython: replace dyn Iterator<..> of sequence with concrete type

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 8, 2019, 10:05 a.m.
Message ID <3c707d5a55e140de8117.1567937143@mimosa>
Download mbox | patch
Permalink /patch/41573/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 8, 2019, 10:05 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1567912039 -32400
#      Sun Sep 08 12:07:19 2019 +0900
# Node ID 3c707d5a55e140de8117893a142c2b17f1a7f401
# Parent  06763fe8317d686dba58464ec4ed74f8325ae825
rust-cpython: replace dyn Iterator<..> of sequence with concrete type

We wouldn't care the cost of the dynamic dispatch, but I feel a concrete
type helps understanding error messages.

Patch

diff --git a/rust/hg-cpython/src/dirstate/dirs_multiset.rs b/rust/hg-cpython/src/dirstate/dirs_multiset.rs
--- a/rust/hg-cpython/src/dirstate/dirs_multiset.rs
+++ b/rust/hg-cpython/src/dirstate/dirs_multiset.rs
@@ -18,7 +18,10 @@  use cpython::{
 
 use crate::dirstate::extract_dirstate;
 use crate::ref_sharing::{PySharedRefCell, PySharedState};
-use hg::{DirsMultiset, DirstateMapError, DirstateParseError, EntryState};
+use hg::{
+    DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError,
+    EntryState,
+};
 
 py_class!(pub class Dirs |py| {
     data inner: PySharedRefCell<DirsMultiset>;
@@ -90,7 +93,7 @@  py_class!(pub class Dirs |py| {
         DirsMultisetKeysIterator::create_instance(
             py,
             RefCell::new(Some(leak_handle)),
-            RefCell::new(Box::new(leaked_ref.iter())),
+            RefCell::new(leaked_ref.iter()),
         )
     }
 
@@ -118,10 +121,10 @@  impl Dirs {
     }
 }
 
-py_shared_sequence_iterator!(
+py_shared_iterator_impl!(
     DirsMultisetKeysIterator,
     DirsMultisetLeakedRef,
-    Vec<u8>,
+    DirsMultisetIter<'static>,
     Dirs::translate_key,
     Option<PyBytes>
 );
diff --git a/rust/hg-cpython/src/ref_sharing.rs b/rust/hg-cpython/src/ref_sharing.rs
--- a/rust/hg-cpython/src/ref_sharing.rs
+++ b/rust/hg-cpython/src/ref_sharing.rs
@@ -417,23 +417,3 @@  macro_rules! py_shared_mapping_iterator 
         );
     };
 }
-
-/// Works basically the same as `py_shared_mapping_iterator`, but with only a
-/// key.
-macro_rules! py_shared_sequence_iterator {
-    (
-        $name:ident,
-        $leaked:ident,
-        $key_type: ty,
-        $success_func: path,
-        $success_type: ty
-    ) => {
-        py_shared_iterator_impl!(
-            $name,
-            $leaked,
-            Box<dyn Iterator<Item = &'static $key_type> + Send>,
-            $success_func,
-            $success_type
-        );
-    };
-}