Fix shared value assignments.

This commit is contained in:
Stephen Chung
2021-03-04 10:24:14 +08:00
parent ade290da7e
commit 2707b887c6
3 changed files with 43 additions and 27 deletions

View File

@@ -944,16 +944,8 @@ impl Dynamic {
pub fn try_cast<T: Variant>(self) -> Option<T> {
// Coded this way in order to maximally leverage potentials for dead-code removal.
match self.0 {
#[cfg(not(feature = "no_closure"))]
#[cfg(not(feature = "sync"))]
Union::Shared(cell, _) => return cell.borrow().clone().try_cast(),
#[cfg(not(feature = "no_closure"))]
#[cfg(feature = "sync")]
Union::Shared(cell, _) => return cell.read().unwrap().clone().try_cast(),
_ => (),
if let Union::Shared(_, _) = self.0 {
return self.flatten().try_cast::<T>();
}
if TypeId::of::<T>() == TypeId::of::<Dynamic>() {
@@ -1321,8 +1313,10 @@ impl Dynamic {
match &self.0 {
Union::Variant(value, _) => value.as_ref().as_ref().as_any().downcast_ref::<T>(),
#[cfg(not(feature = "no_closure"))]
Union::Shared(_, _) => None,
_ => None,
}
}
@@ -1411,8 +1405,10 @@ impl Dynamic {
match &mut self.0 {
Union::Variant(value, _) => value.as_mut().as_mut_any().downcast_mut::<T>(),
#[cfg(not(feature = "no_closure"))]
Union::Shared(_, _) => None,
_ => None,
}
}