Make Engine Send+Sync.

This commit is contained in:
Stephen Chung
2020-04-03 17:17:00 +08:00
parent 9d7091ad9d
commit a79f2a209c
5 changed files with 108 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
//! Helper module that allows registration of the _core library_ and
//! _standard library_ of utility functions.
use crate::any::Any;
use crate::any::{Any, Dynamic};
use crate::engine::{Engine, FUNC_TO_STRING, KEYWORD_DEBUG, KEYWORD_PRINT};
use crate::fn_register::{RegisterDynamicFn, RegisterFn, RegisterResultFn};
use crate::parser::{Position, INT};
@@ -612,8 +612,9 @@ impl Engine<'_> {
reg_fn1!(self, KEYWORD_DEBUG, to_debug, String, Array);
// Register array iterator
self.register_iterator::<Array, _>(|a| {
self.register_iterator::<Array, _>(|a: &Dynamic| {
Box::new(a.downcast_ref::<Array>().unwrap().clone().into_iter())
as Box<dyn Iterator<Item = Dynamic>>
});
}
@@ -636,13 +637,13 @@ impl Engine<'_> {
where
Range<T>: Iterator<Item = T>,
{
engine.register_iterator::<Range<T>, _>(|a| {
engine.register_iterator::<Range<T>, _>(|a: &Dynamic| {
Box::new(
a.downcast_ref::<Range<T>>()
.unwrap()
.clone()
.map(|n| n.into_dynamic()),
)
) as Box<dyn Iterator<Item = Dynamic>>
});
}