Trait tuplez::Foreach

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

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

Traverse the tuple by immutable references to its elements.

§The Functor F

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

See the documentation page of Mapper for details.

Required Associated Types§

source

type Output: TupleLike

The type of tuple generated by traversing the tuple.

Required Methods§

source

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

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

§Example
use tuplez::*;

let tup = tuple!(1, "hello", 3.14).foreach(mapper!{
    x: i32 => i64: *x as i64;
    x: f32 => String: x.to_string();
    x, 'a: &'a str => &'a [u8]: x.as_bytes()
});
assert_eq!(tup, tuple!(1i64, b"hello" as &[u8], "3.14".to_string()));

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F> Foreach<F> for Unit

§

type Output = Unit

source§

impl<F, First, Other> Foreach<F> for Tuple<First, Other>
where F: Mapper<First>, Other: Foreach<F>,

§

type Output = Tuple<<F as Mapper<First>>::Output, <Other as Foreach<F>>::Output>