MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / next

Method next

src/objects/iterator.rs:72–84  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)]

Callers

nothing calls this directly

Calls 1

as_ptrMethod · 0.45

Tested by

no test coverage detected