[][src]Struct pyo3::types::PyIterator

pub struct PyIterator<'p>(_);

A Python iterator object.

Unlike other Python objects, this class includes a Python<'p> token so that PyIterator can implement the Rust Iterator trait.

Example

use pyo3::types::PyIterator;

let gil = Python::acquire_gil();
let py = gil.python();
let list = py.eval("iter([1, 2, 3, 4])", None, None)?;
let numbers: PyResult<Vec<usize>> = list.iter()?.map(|i| i.and_then(PyAny::extract::<usize>)).collect();
let sum: usize = numbers?.iter().sum();
assert_eq!(sum, 10);

Implementations

impl<'p> PyIterator<'p>[src]

pub fn from_object<T>(py: Python<'p>, obj: &T) -> PyResult<PyIterator<'p>> where
    T: AsPyPointer
[src]

Constructs a PyIterator from a Python iterator object.

Trait Implementations

impl<'p> Debug for PyIterator<'p>[src]

impl<'p> Drop for PyIterator<'p>[src]

Dropping a PyIterator instance decrements the reference count on the object by 1.

impl<'p> Iterator for PyIterator<'p>[src]

type Item = PyResult<&'p PyAny>

The type of the elements being iterated over.

fn next(&mut self) -> Option<Self::Item>[src]

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.

Auto Trait Implementations

impl<'p> !RefUnwindSafe for PyIterator<'p>

impl<'p> !Send for PyIterator<'p>

impl<'p> !Sync for PyIterator<'p>

impl<'p> Unpin for PyIterator<'p>

impl<'p> !UnwindSafe for PyIterator<'p>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> FromPy<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> IntoPy<U> for T where
    U: FromPy<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.