Retrieves the next item from an iterator. Returns `None` when the iterator is exhausted. If an exception occurs, returns `Some(Err(..))`. Further next() calls after an exception occurs are likely to repeatedly result in the same exception.
(&mut self)
| 70 | /// Further next() calls after an exception occurs are likely |
| 71 | /// to repeatedly result in the same exception. |
| 72 | fn next(&mut self) -> Option<PyResult<PyObject>> { |
| 73 | let py = self.py; |
| 74 | match unsafe { PyObject::from_owned_ptr_opt(py, ffi::PyIter_Next(self.iter.as_ptr())) } { |
| 75 | Some(obj) => Some(Ok(obj)), |
| 76 | None => { |
| 77 | if PyErr::occurred(py) { |
| 78 | Some(Err(PyErr::fetch(py))) |
| 79 | } else { |
| 80 | None |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | #[cfg(test)] |