Trait tuplez::ForeachOnce

source ·
pub trait ForeachOnce<F>: TupleLike {
    type Output: TupleLike;

    // Required method
    fn foreach_once(self, f: &mut F) -> Self::Output;
}
Expand description

Traverse the tuple by taking its elements.

§The Functor F

For traversing Tuple<T0, T1, ... Tn>, you need to construct a custom functor type, which needs to implement MapperOnce<T0>, MapperOnce<T1>MapperOnce<Tn>.

See the documentation page of MapperOnce for details.

Required Associated Types§

source

type Output: TupleLike

The type of tuple generated by traversing the tuple.

Required Methods§

source

fn foreach_once(self, f: &mut F) -> Self::Output

Traverse the tuple by take its elements, and collect the output of traversal into a new tuple.

§Example
use tuplez::*;

let tup = tuple!(vec![1, 2, 3], "hello".to_string());
let tup2 = tup.foreach_once(mapper_once!{
    x: Vec<i32> => Box<[i32]> : x.into();
    x: String : x
});
// assert_eq!(tup, ... ); // No, `tup` has been moved
assert_eq!(
    tup2,
    tuple!(
        Box::<[i32; 3]>::new([1, 2, 3]) as Box<[i32]>,
        "hello".to_string()
    )
);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F> ForeachOnce<F> for Unit

§

type Output = Unit

source§

impl<F, First, Other> ForeachOnce<F> for Tuple<First, Other>
where F: MapperOnce<First>, Other: ForeachOnce<F>,

§

type Output = Tuple<<F as MapperOnce<First>>::Output, <Other as ForeachOnce<F>>::Output>