Remove reify_dynamic.

This commit is contained in:
Stephen Chung 2022-02-07 12:02:00 +08:00
parent becbfa8930
commit bd9519e96b
2 changed files with 3 additions and 20 deletions

View File

@ -7,7 +7,7 @@ macro_rules! reify {
#[allow(unused_imports)] #[allow(unused_imports)]
use std::any::Any; use std::any::Any;
if std::any::TypeId::of::<$t>() == $old.type_id() { if std::any::TypeId::of::<$t>() == std::any::Any::type_id(&$old) {
// SAFETY: This is safe because we check to make sure the two types are // SAFETY: This is safe because we check to make sure the two types are
// actually the same type. // actually the same type.
let $new: $t = unsafe { std::mem::transmute_copy(&std::mem::ManuallyDrop::new($old)) }; let $new: $t = unsafe { std::mem::transmute_copy(&std::mem::ManuallyDrop::new($old)) };
@ -27,20 +27,3 @@ macro_rules! reify {
reify!($old, |$new: $t| $code, || ()) reify!($old, |$new: $t| $code, || ())
}; };
} }
#[macro_export]
macro_rules! reify_dynamic {
($old:ident, |$new:ident : $t:ty| $code:expr) => {{
#[allow(unused_imports)]
use ::std::{
any::{Any, TypeId},
mem::{transmute_copy, ManuallyDrop},
};
if TypeId::of::<$t>() == TypeId::of::<crate::Dynamic>() {
// SAFETY: This is safe because we check to make sure the two types are
// actually the same type.
let $new: $t = unsafe { transmute_copy(&ManuallyDrop::new($old)) };
$code
}
}};
}

View File

@ -1,7 +1,7 @@
//! Helper module which defines the [`Any`] trait to to allow dynamic value handling. //! Helper module which defines the [`Any`] trait to to allow dynamic value handling.
use crate::func::native::SendSync; use crate::func::native::SendSync;
use crate::{reify, reify_dynamic, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, INT}; use crate::{reify, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, INT};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
use std::{ use std::{
@ -1270,7 +1270,7 @@ impl Dynamic {
return self.flatten().try_cast::<T>(); return self.flatten().try_cast::<T>();
} }
reify_dynamic!(self, |v: T| return Some(v)); reify!(self, |v: T| return Some(v));
match self.0 { match self.0 {
Union::Int(v, ..) => reify!(v, |v: T| Some(v), || None), Union::Int(v, ..) => reify!(v, |v: T| Some(v), || None),