[][src]Struct lhlist::iter::ConsIterator

pub struct ConsIterator<'a, List, A = Nil> { /* fields omitted */ }

An iterator over a heterogeneous cons-list (Cons);

For a version that iterates over only the values of a labeled cons-list (LVCons), see ValuesIterator.

This object is usually created by calling iter on a list.

Example

This example demonstrates building and iterating over the LabeledValues of a heterogeneous cons-list.

use lhlist::{Label, labeled};

new_label![Label1: Vec<usize>];
new_label![Label2: Vec<&'static str>];
new_label![Label3: Vec<f64>];

let test_list = lhlist![
    Label1 = vec![8usize, 4, 1, 5, 2],
    Label2 = vec!["Hello", "World!"],
    Label3 = vec![0.4f64, -3.5, 3.5, 0.3],
];
let iter = test_list.iter();

let (item, iter) = iter.next();
assert_eq!(item, &labeled(Label1, vec![8usize, 4, 1, 5, 2]));
let (item, iter) = iter.next();
assert_eq!(item, &labeled(Label2, vec!["Hello", "World!"]));
let (item, _) = iter.next();
assert_eq!(item, &labeled(Label3, vec![0.4f64, -3.5, 3.5, 0.3]));

Methods

impl<'a, List> ConsIterator<'a, List>[src]

pub fn new(list: &'a List) -> Self[src]

Creates a new ConsIterator over an Cons-list

impl<'a, List, A> ConsIterator<'a, List, A>[src]

pub fn with_adapter(list: &'a List, adapter: A) -> Self[src]

Creates a new ConsIterator over an Cons-list with an adapter (see Adapter).

impl<'a, H, T, A> ConsIterator<'a, Cons<H, T>, A> where
    A: Adapter<&'a H>, 
[src]

pub fn next(self) -> (<A as Adapter<&'a H>>::Output, ConsIterator<'a, T, A>)[src]

Returns the next value (if exists) along with a new iterator advanced to the next element of the list.

pub fn map<F>(
    self,
    f: F
) -> ConsIterator<'a, Cons<H, T>, Cons<MapAdapter<F>, A>> where
    F: MapFunc<<A as Adapter<&'a H>>::Output>, 
[src]

Creates an iterator which call a MapFunc on each element.

See MapAdapter for more information.

pub fn collect_into_labeled_hlist<LabelList>(self) -> Self::Output where
    Self: CollectIntoLabeledHList<LabelList>, 
[src]

Collects this iterator into a new labeled heterogeneous list

For an example of usage, see the MapAdapter example.

Trait Implementations

impl<'a, A> CollectIntoHList for ConsIterator<'a, Nil, A>[src]

type Output = Nil

Output type of collected list

impl<'a, A, H, T> CollectIntoHList for ConsIterator<'a, Cons<H, T>, A> where
    A: Adapter<&'a H>,
    ConsIterator<'a, T, A>: CollectIntoHList
[src]

type Output = Cons<<A as Adapter<&'a H>>::Output, <ConsIterator<'a, T, A> as CollectIntoHList>::Output>

Output type of collected list

impl<'a, A> CollectIntoLabeledHList<Nil> for ConsIterator<'a, Nil, A>[src]

type Output = Nil

Output type of collected list

impl<'a, TargetL, TargetT, A, L, T> CollectIntoLabeledHList<Cons<PhantomData<TargetL>, TargetT>> for ConsIterator<'a, LVCons<L, T>, A> where
    L: Label,
    TargetL: Label,
    A: Adapter<&'a LabeledValue<L>, Output = TargetL::AssocType>,
    ConsIterator<'a, T, A>: CollectIntoLabeledHList<TargetT>, 
[src]

type Output = LVCons<TargetL, <ConsIterator<'a, T, A> as CollectIntoLabeledHList<TargetT>>::Output>

Output type of collected list

impl<'a, List: Debug, A: Debug> Debug for ConsIterator<'a, List, A>[src]

Auto Trait Implementations

impl<'a, List, A> Send for ConsIterator<'a, List, A> where
    A: Send,
    List: Sync

impl<'a, List, A> Sync for ConsIterator<'a, List, A> where
    A: Sync,
    List: Sync

Blanket Implementations

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

impl<T> From<T> for 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.

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

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

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

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

type Output = T

Should always be Self