diff --git a/src/dynamic.rs b/src/dynamic.rs index 4ae4d80f..cc0ca5c7 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -188,11 +188,11 @@ pub enum Union { /// This data structure provides transparent interoperability between /// normal [`Dynamic`] and shared [`Dynamic`] values. #[derive(Debug)] -pub struct DynamicReadLock<'d, T: Variant + Clone>(DynamicReadLockInner<'d, T>); +pub struct DynamicReadLock<'d, T: Clone>(DynamicReadLockInner<'d, T>); /// Different types of read guards for [`DynamicReadLock`]. #[derive(Debug)] -enum DynamicReadLockInner<'d, T: Variant + Clone> { +enum DynamicReadLockInner<'d, T: Clone> { /// A simple reference to a non-shared value. Reference(&'d T), @@ -206,7 +206,7 @@ enum DynamicReadLockInner<'d, T: Variant + Clone> { Guard(std::sync::RwLockReadGuard<'d, Dynamic>), } -impl<'d, T: Variant + Clone> Deref for DynamicReadLock<'d, T> { +impl<'d, T: Any + Clone> Deref for DynamicReadLock<'d, T> { type Target = T; #[inline(always)] @@ -225,11 +225,11 @@ impl<'d, T: Variant + Clone> Deref for DynamicReadLock<'d, T> { /// This data structure provides transparent interoperability between /// normal [`Dynamic`] and shared [`Dynamic`] values. #[derive(Debug)] -pub struct DynamicWriteLock<'d, T: Variant + Clone>(DynamicWriteLockInner<'d, T>); +pub struct DynamicWriteLock<'d, T: Clone>(DynamicWriteLockInner<'d, T>); /// Different types of write guards for [`DynamicReadLock`]. #[derive(Debug)] -enum DynamicWriteLockInner<'d, T: Variant + Clone> { +enum DynamicWriteLockInner<'d, T: Clone> { /// A simple mutable reference to a non-shared value. Reference(&'d mut T), @@ -243,7 +243,7 @@ enum DynamicWriteLockInner<'d, T: Variant + Clone> { Guard(std::sync::RwLockWriteGuard<'d, Dynamic>), } -impl<'d, T: Variant + Clone> Deref for DynamicWriteLock<'d, T> { +impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> { type Target = T; #[inline(always)] @@ -257,7 +257,7 @@ impl<'d, T: Variant + Clone> Deref for DynamicWriteLock<'d, T> { } } -impl<'d, T: Variant + Clone> DerefMut for DynamicWriteLock<'d, T> { +impl<'d, T: Any + Clone> DerefMut for DynamicWriteLock<'d, T> { #[inline(always)] fn deref_mut(&mut self) -> &mut Self::Target { match &mut self.0 { @@ -298,7 +298,7 @@ impl Dynamic { /// If the [`Dynamic`] is a shared variant checking is performed on /// top of its internal value. #[inline(always)] - pub fn is(&self) -> bool { + pub fn is(&self) -> bool { let mut target_type_id = TypeId::of::(); if target_type_id == TypeId::of::() { @@ -983,7 +983,7 @@ impl Dynamic { /// assert_eq!(x.try_cast::().unwrap(), 42); /// ``` #[inline(always)] - pub fn try_cast(self) -> Option { + pub fn try_cast(self) -> Option { // Coded this way in order to maximally leverage potentials for dead-code removal. #[cfg(not(feature = "no_closure"))] @@ -1118,7 +1118,7 @@ impl Dynamic { /// assert_eq!(x.cast::(), 42); /// ``` #[inline(always)] - pub fn cast(self) -> T { + pub fn cast(self) -> T { #[cfg(not(feature = "no_closure"))] let self_type_name = if self.is_shared() { // Avoid panics/deadlocks with shared values @@ -1165,7 +1165,7 @@ impl Dynamic { /// assert_eq!(y.clone_cast::(), 42); /// ``` #[inline(always)] - pub fn clone_cast(&self) -> T { + pub fn clone_cast(&self) -> T { self.read_lock::().unwrap().clone() } /// Flatten the [`Dynamic`] and clone it. @@ -1293,7 +1293,7 @@ impl Dynamic { /// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1). /// Otherwise, this call panics if the data is currently borrowed for write. #[inline(always)] - pub fn read_lock(&self) -> Option> { + pub fn read_lock(&self) -> Option> { match self.0 { #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, _) => { @@ -1326,7 +1326,7 @@ impl Dynamic { /// Under the `sync` feature, this call may deadlock, or [panic](https://doc.rust-lang.org/std/sync/struct.RwLock.html#panics-1). /// Otherwise, this call panics if the data is currently borrowed for write. #[inline(always)] - pub fn write_lock(&mut self) -> Option> { + pub fn write_lock(&mut self) -> Option> { match self.0 { #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, _) => { @@ -1354,7 +1354,7 @@ impl Dynamic { /// /// Returns [`None`] if the cast fails, or if the value is shared. #[inline(always)] - pub(crate) fn downcast_ref(&self) -> Option<&T> { + pub(crate) fn downcast_ref(&self) -> Option<&T> { // Coded this way in order to maximally leverage potentials for dead-code removal. if TypeId::of::() == TypeId::of::() { @@ -1450,7 +1450,7 @@ impl Dynamic { /// /// Returns [`None`] if the cast fails, or if the value is shared. #[inline(always)] - pub(crate) fn downcast_mut(&mut self) -> Option<&mut T> { + pub(crate) fn downcast_mut(&mut self) -> Option<&mut T> { // Coded this way in order to maximally leverage potentials for dead-code removal. if TypeId::of::() == TypeId::of::() { diff --git a/src/unsafe.rs b/src/unsafe.rs index 54cbab67..01e663aa 100644 --- a/src/unsafe.rs +++ b/src/unsafe.rs @@ -1,6 +1,5 @@ //! A helper module containing unsafe utility functions. -use crate::dynamic::Variant; #[cfg(feature = "no_std")] use std::prelude::v1::*; use std::{ @@ -27,7 +26,7 @@ pub fn unsafe_try_cast(a: A) -> Result { /// Cast a Boxed type into another type. #[inline(always)] -pub fn unsafe_cast_box(item: Box) -> Result, Box> { +pub fn unsafe_cast_box(item: Box) -> Result, Box> { // Only allow casting to the exact same type if TypeId::of::() == TypeId::of::() { // SAFETY: just checked whether we are pointing to the correct type diff --git a/tests/arrays.rs b/tests/arrays.rs index 15aa06e7..3760305d 100644 --- a/tests/arrays.rs +++ b/tests/arrays.rs @@ -157,47 +157,43 @@ fn test_arrays_map_reduce() -> Result<(), Box> { let engine = Engine::new(); assert_eq!( - engine.eval::( + convert_to_vec::(engine.eval( r" let x = [1, 2, 3]; - let y = x.filter(|v| v > 2); - y[0] + x.filter(|v| v > 2) " - )?, - 3 + )?), + [3] ); assert_eq!( - engine.eval::( + convert_to_vec::(engine.eval( r" let x = [1, 2, 3]; - let y = x.filter(|v, i| v > i); - y.len() + x.filter(|v, i| v > i) " - )?, - 3 + )?), + [1, 2, 3] ); assert_eq!( - engine.eval::( + convert_to_vec::(engine.eval( r" let x = [1, 2, 3]; - let y = x.map(|v| v * 2); - y[2] + x.map(|v| v * 2) " - )?, - 6 + )?), + [2, 4, 6] ); assert_eq!( - engine.eval::( + convert_to_vec::(engine.eval( r" let x = [1, 2, 3]; - let y = x.map(|v, i| v * i); - y[2] + x.map(|v, i| v * i) " - )?, - 6 + )?), + [0, 2, 6] ); assert_eq!(