no_std_http/convert.rs
1#[macro_export]
2macro_rules! if_downcast_into {
3 ($in_ty:ty, $out_ty:ty, $val:ident, $body:expr) => {{
4 if core::any::TypeId::of::<$in_ty>() == core::any::TypeId::of::<$out_ty>() {
5 // Store the value in an `Option` so we can `take`
6 // it after casting to `&mut dyn Any`.
7 let mut slot = Some($val);
8 // Re-write the `$val` ident with the downcasted value.
9 let $val = (&mut slot as &mut dyn core::any::Any)
10 .downcast_mut::<Option<$out_ty>>()
11 .unwrap()
12 .take()
13 .unwrap();
14 // Run the $body in scope of the replaced val.
15 $body
16 }
17 }};
18}