1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#[macro_export] macro_rules! new_flattened { ($value:expr, $container:ident) => { $container::new($value) }; ($value:expr, $container:ident, $($containers:ident),+) => { $container::new(new_flattened!($value, $($containers),+)) }; } #[cfg(test)] mod tests { #[test] fn simple() { assert_eq!( Box::new(Box::new(Box::new(5))), new_flattened!(5, Box, Box, Box), ); } }