Fix sync.
This commit is contained in:
parent
799dd9d9d1
commit
db865d7538
@ -292,7 +292,7 @@ impl Engine {
|
||||
.set_custom_type_raw(fully_qualified_type_path, name);
|
||||
self
|
||||
}
|
||||
/// Register an type iterator for an iterable type with the [`Engine`].
|
||||
/// Register a type iterator for an iterable type with the [`Engine`].
|
||||
/// This is an advanced API.
|
||||
#[inline(always)]
|
||||
pub fn register_iterator<T>(&mut self) -> &mut Self
|
||||
@ -303,6 +303,17 @@ impl Engine {
|
||||
self.global_namespace_mut().set_iterable::<T>();
|
||||
self
|
||||
}
|
||||
/// Register a fallible type iterator for an iterable type with the [`Engine`].
|
||||
/// This is an advanced API.
|
||||
#[inline(always)]
|
||||
pub fn register_iterator_result<T, X>(&mut self) -> &mut Self
|
||||
where
|
||||
T: Variant + Clone + IntoIterator<Item = RhaiResultOf<X>>,
|
||||
X: Variant + Clone,
|
||||
{
|
||||
self.global_namespace_mut().set_iterable_result::<T, X>();
|
||||
self
|
||||
}
|
||||
/// Register a getter function for a member of a registered type with the [`Engine`].
|
||||
///
|
||||
/// The function signature must start with `&mut self` and not `&self`.
|
||||
|
@ -2250,12 +2250,11 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Set a type iterator into the [`Module`].
|
||||
#[cfg(not(feature = "sync"))]
|
||||
#[inline(always)]
|
||||
pub fn set_iter(
|
||||
&mut self,
|
||||
type_id: TypeId,
|
||||
func: impl Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>> + 'static,
|
||||
func: impl Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>> + SendSync + 'static,
|
||||
) -> &mut Self {
|
||||
self.set_iter_result(type_id, move |x| {
|
||||
Box::new(func(x).map(Ok)) as Box<dyn Iterator<Item = RhaiResultOf<Dynamic>>>
|
||||
@ -2263,12 +2262,11 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Set a fallible type iterator into the [`Module`].
|
||||
#[cfg(not(feature = "sync"))]
|
||||
#[inline]
|
||||
pub fn set_iter_result(
|
||||
&mut self,
|
||||
type_id: TypeId,
|
||||
func: impl Fn(Dynamic) -> Box<dyn Iterator<Item = RhaiResultOf<Dynamic>>> + 'static,
|
||||
func: impl Fn(Dynamic) -> Box<dyn Iterator<Item = RhaiResultOf<Dynamic>>> + SendSync + 'static,
|
||||
) -> &mut Self {
|
||||
let func = Shared::new(func);
|
||||
if self.indexed {
|
||||
@ -2280,24 +2278,7 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Set a type iterator into the [`Module`].
|
||||
#[cfg(feature = "sync")]
|
||||
#[inline]
|
||||
pub fn set_iter(
|
||||
&mut self,
|
||||
type_id: TypeId,
|
||||
func: impl Fn(Dynamic) -> Box<dyn Iterator<Item = Dynamic>> + SendSync + 'static,
|
||||
) -> &mut Self {
|
||||
let func = Shared::new(func);
|
||||
if self.indexed {
|
||||
self.all_type_iterators.insert(type_id, func.clone());
|
||||
self.contains_indexed_global_functions = true;
|
||||
}
|
||||
self.type_iterators.insert(type_id, func);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set a type iterator into the [`Module`].
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
pub fn set_iterable<T>(&mut self) -> &mut Self
|
||||
where
|
||||
T: Variant + Clone + IntoIterator,
|
||||
@ -2308,8 +2289,20 @@ impl Module {
|
||||
})
|
||||
}
|
||||
|
||||
/// Set a fallible type iterator into the [`Module`].
|
||||
#[inline(always)]
|
||||
pub fn set_iterable_result<T, X>(&mut self) -> &mut Self
|
||||
where
|
||||
T: Variant + Clone + IntoIterator<Item = RhaiResultOf<X>>,
|
||||
X: Variant + Clone,
|
||||
{
|
||||
self.set_iter_result(TypeId::of::<T>(), |obj: Dynamic| {
|
||||
Box::new(obj.cast::<T>().into_iter().map(|v| v.map(Dynamic::from)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Set an iterator type into the [`Module`] as a type iterator.
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
pub fn set_iterator<T>(&mut self) -> &mut Self
|
||||
where
|
||||
T: Variant + Clone + Iterator,
|
||||
@ -2320,6 +2313,18 @@ impl Module {
|
||||
})
|
||||
}
|
||||
|
||||
/// Set a iterator type into the [`Module`] as a fallible type iterator.
|
||||
#[inline(always)]
|
||||
pub fn set_iterator_result<T, X>(&mut self) -> &mut Self
|
||||
where
|
||||
T: Variant + Clone + Iterator<Item = RhaiResultOf<X>>,
|
||||
X: Variant + Clone,
|
||||
{
|
||||
self.set_iter_result(TypeId::of::<T>(), |obj: Dynamic| {
|
||||
Box::new(obj.cast::<T>().map(|v| v.map(Dynamic::from)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the specified type iterator.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user