Macro tuplez::mapper_mut

source ·
macro_rules! mapper_mut {
    ($($x:ident $(, $lt:lifetime)*: $it:ty $(=> $ot:ty)? : $e:expr);* $(;)?) => { ... };
    ($($x:ident $(, $lt:lifetime)*: $it:ty $(=> $ot:ty)? : $e:expr ;)*
        $(_ $(=> $ot2:ty)? : $f:ident $(where $($t:tt)*)?)?) => { ... };
    (@impl _ : $f:ident $(where $($t:tt)*)?) => { ... };
    (@impl _ => $ot:ty : $f:ident $(where $($t:tt)*)?) => { ... };
    (@impl $x:ident : $it:ty : $e:expr) => { ... };
    (@impl $x:ident $(, $lt:lifetime)* : $it:ty : $e:expr) => { ... };
    (@impl $x:ident : $it:ty => $ot:ty : $e:expr) => { ... };
    (@impl $x:ident $(, $lt:lifetime)* : $it:ty => $ot:ty : $e:expr) => { ... };
}
Expand description

Provides a simple way to create a functor that implements MapperMut.

§Syntax

The syntax is exactly the same as mapper!. The difference is that mapper_mut! passes in mutable references to the elements of the tuple instead of immutable references.

§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", ()));