Trait tuplez::ForeachMut

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

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

Traverse the tuple by mutable 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 MapperMut<T0>, MapperMut<T1>MapperMut<Tn>.

See the documentation page of MapperMut for details.

Required Associated Types§

source

type Output: TupleLike

The type of tuple generated by traversing the tuple.

Required Methods§

source

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

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

§Example
use tuplez::*;

let mut tup = tuple!(2, "hello", 3.14);
let tup2 = tup.foreach_mut(mapper_mut!{
    x: i32: { (*x) *= (*x); *x - 1 };
    x: f32 => (): *x += 1.0;
    x, 'a: &'a str: *x
});
assert_eq!(tup, tuple!(4, "hello", 3.14 + 1.0));
assert_eq!(tup2, tuple!(3, "hello", ()));

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F> ForeachMut<F> for Unit

§

type Output = Unit

source§

impl<F, First, Other> ForeachMut<F> for Tuple<First, Other>
where F: MapperMut<First>, Other: ForeachMut<F>,

§

type Output = Tuple<<F as MapperMut<First>>::Output, <Other as ForeachMut<F>>::Output>