Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirs_multiset.rs @ 42887:706104dcb2c8
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 08 Sep 2019 12:07:19 +0900 |
parents | 64e28b891796 |
children | ea91a126c803 |
comparison
equal
deleted
inserted
replaced
42886:7083ac37314f | 42887:706104dcb2c8 |
---|---|
16 Python, | 16 Python, |
17 }; | 17 }; |
18 | 18 |
19 use crate::dirstate::extract_dirstate; | 19 use crate::dirstate::extract_dirstate; |
20 use crate::ref_sharing::{PySharedRefCell, PySharedState}; | 20 use crate::ref_sharing::{PySharedRefCell, PySharedState}; |
21 use hg::{DirsMultiset, DirstateMapError, DirstateParseError, EntryState}; | 21 use hg::{ |
22 DirsMultiset, DirsMultisetIter, DirstateMapError, DirstateParseError, | |
23 EntryState, | |
24 }; | |
22 | 25 |
23 py_class!(pub class Dirs |py| { | 26 py_class!(pub class Dirs |py| { |
24 data inner: PySharedRefCell<DirsMultiset>; | 27 data inner: PySharedRefCell<DirsMultiset>; |
25 data py_shared_state: PySharedState; | 28 data py_shared_state: PySharedState; |
26 | 29 |
88 def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> { | 91 def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> { |
89 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; | 92 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; |
90 DirsMultisetKeysIterator::create_instance( | 93 DirsMultisetKeysIterator::create_instance( |
91 py, | 94 py, |
92 RefCell::new(Some(leak_handle)), | 95 RefCell::new(Some(leak_handle)), |
93 RefCell::new(Box::new(leaked_ref.iter())), | 96 RefCell::new(leaked_ref.iter()), |
94 ) | 97 ) |
95 } | 98 } |
96 | 99 |
97 def __contains__(&self, item: PyObject) -> PyResult<bool> { | 100 def __contains__(&self, item: PyObject) -> PyResult<bool> { |
98 Ok(self | 101 Ok(self |
116 fn translate_key(py: Python, res: &Vec<u8>) -> PyResult<Option<PyBytes>> { | 119 fn translate_key(py: Python, res: &Vec<u8>) -> PyResult<Option<PyBytes>> { |
117 Ok(Some(PyBytes::new(py, res))) | 120 Ok(Some(PyBytes::new(py, res))) |
118 } | 121 } |
119 } | 122 } |
120 | 123 |
121 py_shared_sequence_iterator!( | 124 py_shared_iterator_impl!( |
122 DirsMultisetKeysIterator, | 125 DirsMultisetKeysIterator, |
123 DirsMultisetLeakedRef, | 126 DirsMultisetLeakedRef, |
124 Vec<u8>, | 127 DirsMultisetIter<'static>, |
125 Dirs::translate_key, | 128 Dirs::translate_key, |
126 Option<PyBytes> | 129 Option<PyBytes> |
127 ); | 130 ); |