[][src]Struct lhlist::Cons

pub struct Cons<H, T> {
    pub head: H,
    pub tail: T,
}

Main buildling block of a heterogeneous list.

Fields

head: H

Value of this element of the list.

tail: T

Remaining elements of the list.

Methods

impl<Head, Tail> Cons<Head, Tail>[src]

pub fn iter<'a>(&'a self) -> ConsIterator<'a, Self>[src]

Returns a iterator over this cons-list.

pub fn has_label<TargetL>(&self, _target_label: TargetL) -> bool where
    Self: Member<TargetL>, 
[src]

Returns true if target label exists in this list.

Convenience function for calling has_label_typearg without needing to specify type argument. Calling list.has_label(ExampleLabel) is equivalent to list.has_label_typearg::<ExampleLabel>()).

pub fn has_label_typearg<TargetL>(&self) -> bool where
    Self: Member<TargetL>, 
[src]

Returns true if target label exists in this list.

Calling list.has_label(ExampleLabel) is equivalent to list.has_label_typearg::<ExampleLabel>()).

pub fn iter_values<'a>(&'a self) -> ValuesIterator<'a, Self>[src]

Returns a iterator over this labeled cons-list which iterates over the lists' values (i.e. object of type Value).

See ValuesIterator for an example.

pub fn elem<TargetL>(&self) -> &Self::Elem where
    Self: LookupElemByLabel<TargetL>, 
[src]

Returns a reference the element labeled by a specific label.

Example

use lhlist::labeled;
new_label![Label1: u8];
new_label![Label2: i8];
new_label![Label3: bool];
let list = lhlist![
    Label1 = 9,
    Label2 = -4,
    Label3 = true,
];
// assert_eq!(list[Label1], labeled(Label1, 9));
assert_eq!(list.elem::<Label1>(), &labeled(Label1, 9));
// assert_eq!(list[Label2], labeled(Label2, -4));
assert_eq!(list.elem::<Label2>(), &labeled(Label2, -4));
// assert_eq!(list[Label3], labeled(Label3, true));
assert_eq!(list.elem::<Label3>(), &labeled(Label3, true));

pub fn elem_mut<TargetL>(&mut self) -> &mut Self::Elem where
    Self: LookupElemByLabelMut<TargetL>, 
[src]

Returns a mutable reference the element labeled by a specific label.

This is equivalent to using index list[Label] notation in a mutable context.

Note that the label itself cannot be changed via this method since labels in lhlist are type-level.

Example

use lhlist::labeled;
new_label![Label1: u8];
new_label![Label2: i8];
new_label![Label3: bool];
let mut list = lhlist![
    Label1 = 9,
    Label2 = -4,
    Label3 = true,
];

let value2 = list.elem_mut::<Label2>();
assert_eq!(value2, &mut labeled(Label2, -4));
*value2 = labeled(Label2, -9);
assert_eq!(list, lhlist![
    Label1 = 9,
    Label2 = -9,
    Label3 = true,
]);

pub fn value<'a, TargetL>(&'a self) -> &'a <Self::Elem as Value>::Output where
    Self: LookupElemByLabel<TargetL>,
    Self::Elem: 'a + Value
[src]

Returns a reference the value (e.g. the value portion of a LabeledValue) labeled by a specific label.

This is equivalent to using index list[Label] notation, with the exception that value also works for transient (non-'static) types.

Example

new_label![Label1: u8];
new_label![Label2: i8];
new_label![Label3: bool];
let list = lhlist![
    Label1 = 9,
    Label2 = -4,
    Label3 = true,
];
assert_eq!(list[Label1], 9);
assert_eq!(list.value::<Label1>(), &9);
assert_eq!(list[Label2], -4);
assert_eq!(list.value::<Label2>(), &-4);
assert_eq!(list[Label3], true);
assert_eq!(list.value::<Label3>(), &true);

pub fn value_mut<'a, TargetL>(
    &'a mut self
) -> &'a mut <Self::Elem as Value>::Output where
    Self: LookupElemByLabelMut<TargetL>,
    Self::Elem: 'a + Value
[src]

Returns a mutable reference the value (e.g. the value portion of a LabeledValue) labeled by a specific label.

This is equivalent to using index list[Label] notation in mut contexts, with the exception that value_mut also works for transient (non-'static) types.

Example

new_label![Label1: u8];
new_label![Label2: i8];
new_label![Label3: bool];
let mut list = lhlist![
    Label1 = 9,
    Label2 = -4,
    Label3 = true,
];

let value2 = list.value_mut::<Label2>();
assert_eq!(value2, &mut -4);
*value2 = -9;
assert_eq!(list, lhlist![
    Label1 = 9,
    Label2 = -9,
    Label3 = true,
]);

list[Label3] = false;
assert_eq!(list, lhlist![
    Label1 = 9,
    Label2 = -9,
    Label3 = false,
]);

Trait Implementations

impl<H, T> Len for Cons<H, T> where
    T: Len
[src]

fn len(&self) -> usize[src]

Returns the length of this list

impl<Lbl: Sized, Tail> StrLabels for Cons<Lbl, Tail> where
    Self: Len + BuildStrLabels, 
[src]

fn labels(&self) -> Vec<&'static str>[src]

Generates the label name Vec using a value

impl<TargetL, L, T> Member<TargetL> for Cons<L, T> where
    L: Label + LabelEq<TargetL>,
    Self: MemberMatch<TargetL, <L as LabelEq<TargetL>>::Output>, 
[src]

type Output = Self::Output

True if TargetL is a member, False otherwise.

impl<TargetL, L, T> LookupElemByLabel<TargetL> for Cons<L, T> where
    L: Label + LabelEq<TargetL>,
    T: Member<TargetL>,
    Self: LookupElemByLabelMatch<TargetL, <L as LabelEq<TargetL>>::Output, <T as Member<TargetL>>::Output>, 
[src]

type Elem = Self::Elem

The type of the returned element

impl<T, Head, Tail> Adapter<T> for Cons<Head, Tail> where
    Tail: Adapter<T>,
    Head: Adapter<<Tail as Adapter<T>>::Output>, 
[src]

type Output = <Head as Adapter<<Tail as Adapter<T>>::Output>>::Output

Transformation output type

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, 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>, 
[src]

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

Output type of collected list

impl<H: Eq, T: Eq> Eq for Cons<H, T>[src]

impl<H: PartialEq, T: PartialEq> PartialEq<Cons<H, T>> for Cons<H, T>[src]

impl<H: Clone, T: Clone> Clone for Cons<H, T>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<H: Debug, T: Debug> Debug for Cons<H, T>[src]

impl<L, H, T> Index<L> for Cons<H, T> where
    Cons<H, T>: LookupElemByLabel<L>,
    <Cons<H, T> as LookupElemByLabel<L>>::Elem: 'static + Value
[src]

type Output = <<Cons<H, T> as LookupElemByLabel<L>>::Elem as Value>::Output

The returned type after indexing.

impl<L, H, T> IndexMut<L> for Cons<H, T> where
    Cons<H, T>: LookupElemByLabelMut<L>,
    <Cons<H, T> as LookupElemByLabel<L>>::Elem: 'static + Value
[src]

impl<H: Hash, T: Hash> Hash for Cons<H, T>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl<H, T> Send for Cons<H, T> where
    H: Send,
    T: Send

impl<H, T> Sync for Cons<H, T> where
    H: Sync,
    T: Sync

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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