From f68c5a699db404c643f61f484003825ea1c37d4c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 8 Aug 2020 17:04:21 +0800 Subject: [PATCH] Fix sync feature. --- src/any.rs | 6 +++--- src/fn_call.rs | 2 +- src/fn_native.rs | 4 ++-- src/scope.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/any.rs b/src/any.rs index 5d47465d..c154a682 100644 --- a/src/any.rs +++ b/src/any.rs @@ -789,13 +789,13 @@ impl Dynamic { self.try_cast::().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 a shared value, it a cloned copy of the shared value. #[inline(always)] - pub fn get_inner_clone(&self) -> Self { + pub fn flatten_clone(&self) -> Self { match &self.0 { #[cfg(not(feature = "no_closure"))] Union::Shared(cell) => { @@ -826,7 +826,7 @@ impl Dynamic { #[cfg(feature = "sync")] 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, } diff --git a/src/fn_call.rs b/src/fn_call.rs index 87cc4e2b..7d5e313a 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -926,7 +926,7 @@ impl Engine { .map_err(|err| err.new_position(pos))?; 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() } else { // Turn it into a method call only if the object is not shared diff --git a/src/fn_native.rs b/src/fn_native.rs index a32e7d8b..3b8e040a 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -52,7 +52,7 @@ pub fn shared_make_mut(value: &mut Shared) -> &mut T { } /// Consume a `Shared` resource if is unique (i.e. not shared). -pub fn shared_try_take(value: Shared) -> Result> { +pub fn shared_try_take(value: Shared) -> Result> { #[cfg(not(feature = "sync"))] return Rc::try_unwrap(value); #[cfg(feature = "sync")] @@ -64,7 +64,7 @@ pub fn shared_try_take(value: Shared) -> Result> { /// # Panics /// /// Panics if the resource is shared (i.e. has other outstanding references). -pub fn shared_take(value: Shared) -> T { +pub fn shared_take(value: Shared) -> T { shared_try_take(value).map_err(|_| ()).unwrap() } diff --git a/src/scope.rs b/src/scope.rs index afc55e72..1e489f0a 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -338,7 +338,7 @@ impl<'a> Scope<'a> { /// ``` pub fn get_value(&self, name: &str) -> Option { 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. @@ -441,7 +441,7 @@ impl<'a> Scope<'a> { /// ``` pub fn iter(&self) -> impl Iterator { 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.