Fix sync feature.

This commit is contained in:
Stephen Chung 2020-08-08 17:04:21 +08:00
parent 5a1a141ce3
commit f68c5a699d
4 changed files with 8 additions and 8 deletions

View File

@ -789,13 +789,13 @@ impl Dynamic {
self.try_cast::<T>().unwrap() self.try_cast::<T>().unwrap()
} }
/// Dereference the `Dynamic`. /// Flatten the `Dynamic` and clone it.
/// ///
/// If the `Dynamic` is not a shared value, it returns a cloned copy. /// If the `Dynamic` is not a shared value, it returns a cloned copy.
/// ///
/// If the `Dynamic` is a shared value, it a cloned copy of the shared value. /// If the `Dynamic` is a shared value, it a cloned copy of the shared value.
#[inline(always)] #[inline(always)]
pub fn get_inner_clone(&self) -> Self { pub fn flatten_clone(&self) -> Self {
match &self.0 { match &self.0 {
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
Union::Shared(cell) => { Union::Shared(cell) => {
@ -826,7 +826,7 @@ impl Dynamic {
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
return shared_try_take(cell) return shared_try_take(cell)
.map_or_else(|c| c.read().unwrap().clone(), RwLock::into_inner); .map_or_else(|c| c.read().unwrap().clone(), |v| v.into_inner().unwrap());
} }
_ => self, _ => self,
} }

View File

@ -926,7 +926,7 @@ impl Engine {
.map_err(|err| err.new_position(pos))?; .map_err(|err| err.new_position(pos))?;
args = if target.is_shared() { args = if target.is_shared() {
arg_values.insert(0, target.get_inner_clone()); arg_values.insert(0, target.flatten_clone());
arg_values.iter_mut().collect() arg_values.iter_mut().collect()
} else { } else {
// Turn it into a method call only if the object is not shared // Turn it into a method call only if the object is not shared

View File

@ -52,7 +52,7 @@ pub fn shared_make_mut<T: Clone>(value: &mut Shared<T>) -> &mut T {
} }
/// Consume a `Shared` resource if is unique (i.e. not shared). /// Consume a `Shared` resource if is unique (i.e. not shared).
pub fn shared_try_take<T: Clone>(value: Shared<T>) -> Result<T, Shared<T>> { pub fn shared_try_take<T>(value: Shared<T>) -> Result<T, Shared<T>> {
#[cfg(not(feature = "sync"))] #[cfg(not(feature = "sync"))]
return Rc::try_unwrap(value); return Rc::try_unwrap(value);
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
@ -64,7 +64,7 @@ pub fn shared_try_take<T: Clone>(value: Shared<T>) -> Result<T, Shared<T>> {
/// # Panics /// # Panics
/// ///
/// Panics if the resource is shared (i.e. has other outstanding references). /// Panics if the resource is shared (i.e. has other outstanding references).
pub fn shared_take<T: Clone>(value: Shared<T>) -> T { pub fn shared_take<T>(value: Shared<T>) -> T {
shared_try_take(value).map_err(|_| ()).unwrap() shared_try_take(value).map_err(|_| ()).unwrap()
} }

View File

@ -338,7 +338,7 @@ impl<'a> Scope<'a> {
/// ``` /// ```
pub fn get_value<T: Variant + Clone>(&self, name: &str) -> Option<T> { pub fn get_value<T: Variant + Clone>(&self, name: &str) -> Option<T> {
self.get_entry(name) self.get_entry(name)
.and_then(|Entry { value, .. }| value.get_inner_clone().try_cast()) .and_then(|Entry { value, .. }| value.flatten_clone().try_cast())
} }
/// Update the value of the named entry. /// Update the value of the named entry.
@ -441,7 +441,7 @@ impl<'a> Scope<'a> {
/// ``` /// ```
pub fn iter(&self) -> impl Iterator<Item = (&str, Dynamic)> { pub fn iter(&self) -> impl Iterator<Item = (&str, Dynamic)> {
self.iter_raw() self.iter_raw()
.map(|(name, value)| (name, value.get_inner_clone())) .map(|(name, value)| (name, value.flatten_clone()))
} }
/// Get an iterator to entries in the Scope. /// Get an iterator to entries in the Scope.