1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#[macro_export] macro_rules! boxed_from_impl { ( $(From<Box<$t:ty>> for Box<$g:ty>);+ ) => { $( impl From<Box<$t>> for Box<$g> where $t: Into<$g> { fn from(boxed: Box<$t>) -> Box<$g> { Box::new((*boxed).into()) } } )+ }; } #[macro_export] macro_rules! boxed_try_from_impl { ( $(TryFrom<Box<$t:ty>> for Box<$g:ty>);+ ) => { $( impl TryFrom<Box<$t>> for Box<$g> where $t: TryInto<$g> { type Error = <$t as TryInto<$g>>::Error; fn try_from(boxed: Box<$t>) -> Result<Box<$g>, Self::Error> { Ok(Box::new((*boxed).try_into()?)) } } )+ }; }