[][src]Struct rustler::ListIterator

pub struct ListIterator<'a> { /* fields omitted */ }

Enables iteration over the items in the list.

Although this behaves like a standard Rust iterator (book / docs), there are a couple of tricky parts to using it.

Because the iterator is an iterator over Terms, you need to decode the terms before you can do anything with them.

Example

An easy way to decode all terms in a list, is to use the .map() function of the iterator, and decode every entry in the list. This will produce an iterator of Results, and will therefore not be directly usable in the way you might immediately expect.

For this case, the the .collect() function of rust iterators is useful, as it can lift the Results out of the list. (Contains extra type annotations for clarity)

let list_iterator: ListIterator = list_term.decode()?;

let result: NifResult<Vec<i64>> = list_iterator
    // Produces an iterator of NifResult<i64>
    .map(|x| x.decode::<i64>())
    // Lifts each value out of the result. Returns Ok(Vec<i64>) if successful, the first error
    // Error(Error) on failure.
    .collect::<NifResult<Vec<i64>>>();

Trait Implementations

impl<'a> Decoder<'a> for ListIterator<'a>[src]

impl<'a> Iterator for ListIterator<'a>[src]

type Item = Term<'a>

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a> RefUnwindSafe for ListIterator<'a>

impl<'a> Send for ListIterator<'a>

impl<'a> Sync for ListIterator<'a>

impl<'a> Unpin for ListIterator<'a>

impl<'a> UnwindSafe for ListIterator<'a>

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, 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> 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.