Struct ValuesIterator

Source
pub struct ValuesIterator<'a, List, A = Nil> { /* private fields */ }
Expand description

An iterator over a labeled heterogeneous cons-list (LVCons) that only provides access to the contained values (as opposed to the LabeledValue object).

For a version that iterates over a cons-list (Cons) without stripping labeled information, see ConsIterator.

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

§Example

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

use lhlist::Label;

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_values();

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

Implementations§

Source§

impl<'a, List> ValuesIterator<'a, List>

Source

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

Creates a new ValuesIterator over an LVCons-list

Source§

impl<'a, List, A> ValuesIterator<'a, List, A>

Source

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

Creates a new ValuesIterator over an LVCons-list with a specified adapter (see Adapter).

Source§

impl<'a, L, T, A> ValuesIterator<'a, LVCons<L, T>, A>
where L: Label, A: Adapter<&'a L::AssocType>,

Source

pub fn next( self, ) -> (<A as Adapter<&'a L::AssocType>>::Output, ValuesIterator<'a, T, A>)

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

Source

pub fn map<F>( self, f: F, ) -> ValuesIterator<'a, LVCons<L, T>, Cons<MapAdapter<F>, A>>
where F: MapFunc<<A as Adapter<&'a L::AssocType>>::Output>,

Creates an iterator which call a MapFunc on each element.

See MapAdapter for more information.

Source

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

Collects this iterator into a new labeled heterogeneous list

For an example of usage, see the MapAdapter example.

Trait Implementations§

Source§

impl<'a, A, L, T> CollectIntoHList for ValuesIterator<'a, LVCons<L, T>, A>
where L: Label, A: Adapter<&'a L::AssocType>, ValuesIterator<'a, T, A>: CollectIntoHList,

Source§

type Output = Cons<<A as Adapter<&'a <L as Label>::AssocType>>::Output, <ValuesIterator<'a, T, A> as CollectIntoHList>::Output>

Output type of collected list
Source§

fn collect_into_hlist(self) -> Self::Output

Collects the contents of an iterator into a cons-list
Source§

impl<'a, A> CollectIntoHList for ValuesIterator<'a, Nil, A>

Source§

type Output = Nil

Output type of collected list
Source§

fn collect_into_hlist(self) -> Self::Output

Collects the contents of an iterator into a cons-list
Source§

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

Source§

type Output = Cons<LabeledValue<TargetL>, <ValuesIterator<'a, T, A> as CollectIntoLabeledHList<TargetT>>::Output>

Output type of collected list
Source§

fn collect_into_labeled_hlist(self) -> Self::Output

Collects the contents of an iterator into a labeled cons-list
Source§

impl<'a, A> CollectIntoLabeledHList<Nil> for ValuesIterator<'a, Nil, A>

Source§

type Output = Nil

Output type of collected list
Source§

fn collect_into_labeled_hlist(self) -> Self::Output

Collects the contents of an iterator into a labeled cons-list
Source§

impl<'a, List: Debug, A: Debug> Debug for ValuesIterator<'a, List, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, List, A> Freeze for ValuesIterator<'a, List, A>
where A: Freeze,

§

impl<'a, List, A> RefUnwindSafe for ValuesIterator<'a, List, A>
where A: RefUnwindSafe, List: RefUnwindSafe,

§

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

§

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

§

impl<'a, List, A> Unpin for ValuesIterator<'a, List, A>
where A: Unpin,

§

impl<'a, List, A> UnwindSafe for ValuesIterator<'a, List, A>
where A: UnwindSafe, List: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.