1 use std::any::TypeId;
2 
transmute_mut_if_eq<A: 'static, B: 'static>(a: &mut A) -> Result<&mut B, &mut A>3 pub(crate) fn transmute_mut_if_eq<A: 'static, B: 'static>(a: &mut A) -> Result<&mut B, &mut A> {
4     if TypeId::of::<A>() == TypeId::of::<B>() {
5         // SAFETY: we check type before transmuting.
6         Ok(unsafe { &mut *(a as *mut A as *mut B) })
7     } else {
8         Err(a)
9     }
10 }
11 
transmute_ref_if_eq<A: 'static, B: 'static>(a: &A) -> Result<&B, &A>12 pub(crate) fn transmute_ref_if_eq<A: 'static, B: 'static>(a: &A) -> Result<&B, &A> {
13     if TypeId::of::<A>() == TypeId::of::<B>() {
14         // SAFETY: we check type before transmuting.
15         Ok(unsafe { &*(a as *const A as *const B) })
16     } else {
17         Err(a)
18     }
19 }
20