Macro tuplez::mapper_once
source · macro_rules! mapper_once { ($($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 MapperOnce.
§Syntax
The syntax is exactly the same as mapper!. The difference is that mapper_once! take elements of the tuple
instead of pass in their immutable references.
§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()
)
);