Use &PyAny instead of PyObject in PyDictIterator
This commit is contained in:
parent
026caeda68
commit
7b502821ce
|
@ -154,19 +154,16 @@ impl PyDict {
|
|||
///
|
||||
/// Note that it's unsafe to use when the dictionary might be changed by other code.
|
||||
pub fn iter(&self) -> PyDictIterator {
|
||||
let py = self.py();
|
||||
PyDictIterator {
|
||||
dict: self.to_object(py),
|
||||
dict: self.as_ref(),
|
||||
pos: 0,
|
||||
py,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PyDictIterator<'py> {
|
||||
dict: PyObject,
|
||||
dict: &'py PyAny,
|
||||
pos: isize,
|
||||
py: Python<'py>,
|
||||
}
|
||||
|
||||
impl<'py> Iterator for PyDictIterator<'py> {
|
||||
|
@ -178,7 +175,7 @@ impl<'py> Iterator for PyDictIterator<'py> {
|
|||
let mut key: *mut ffi::PyObject = std::ptr::null_mut();
|
||||
let mut value: *mut ffi::PyObject = std::ptr::null_mut();
|
||||
if ffi::PyDict_Next(self.dict.as_ptr(), &mut self.pos, &mut key, &mut value) != 0 {
|
||||
let py = self.py;
|
||||
let py = self.dict.py();
|
||||
Some((py.from_borrowed_ptr(key), py.from_borrowed_ptr(value)))
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -101,7 +101,10 @@ impl PySet {
|
|||
/// Note that it can be unsafe to use when the set might be changed by other code.
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
pub fn iter(&self) -> PySetIterator {
|
||||
self.into_iter()
|
||||
PySetIterator {
|
||||
set: self.as_ref(),
|
||||
pos: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,10 +138,7 @@ impl<'a> std::iter::IntoIterator for &'a PySet {
|
|||
type IntoIter = PySetIterator<'a>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
PySetIterator {
|
||||
set: self.as_ref(),
|
||||
pos: 0,
|
||||
}
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue