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§
Required Methods§
sourcefn foreach(&self, f: &mut F) -> Self::Output
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.