diff --git a/src/api/build_type.rs b/src/api/build_type.rs
index 8fa940e7..08b483d0 100644
--- a/src/api/build_type.rs
+++ b/src/api/build_type.rs
@@ -117,10 +117,10 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
/// Register a custom function.
#[inline(always)]
- pub fn with_fn(
+ pub fn with_fn(
&mut self,
name: impl AsRef + Into,
- method: impl RegisterNativeFunction,
+ method: impl RegisterNativeFunction,
) -> &mut Self {
self.engine.register_fn(name, method);
self
@@ -149,10 +149,10 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
///
/// Not available under `no_object`.
#[inline(always)]
- pub fn with_get(
+ pub fn with_get(
&mut self,
name: impl AsRef,
- get_fn: impl RegisterNativeFunction<(Mut,), 1, V, S> + crate::func::SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut,), 1, C, V, L> + crate::func::SendSync + 'static,
) -> &mut Self {
self.engine.register_get(name, get_fn);
self
@@ -162,10 +162,10 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
///
/// Not available under `no_object`.
#[inline(always)]
- pub fn with_set(
+ pub fn with_set(
&mut self,
name: impl AsRef,
- set_fn: impl RegisterNativeFunction<(Mut, V), 2, (), S> + crate::func::SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, V), 2, C, (), L> + crate::func::SendSync + 'static,
) -> &mut Self {
self.engine.register_set(name, set_fn);
self
@@ -177,11 +177,19 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
///
/// Not available under `no_object`.
#[inline(always)]
- pub fn with_get_set(
+ pub fn with_get_set<
+ const C1: bool,
+ const C2: bool,
+ V: Variant + Clone,
+ const L1: bool,
+ const L2: bool,
+ >(
&mut self,
name: impl AsRef,
- get_fn: impl RegisterNativeFunction<(Mut,), 1, V, S1> + crate::func::SendSync + 'static,
- set_fn: impl RegisterNativeFunction<(Mut, V), 2, (), S2> + crate::func::SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut,), 1, C1, V, L1> + crate::func::SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, V), 2, C2, (), L2>
+ + crate::func::SendSync
+ + 'static,
) -> &mut Self {
self.engine.register_get_set(name, get_fn, set_fn);
self
@@ -196,9 +204,14 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
///
/// Not available under both `no_index` and `no_object`.
#[inline(always)]
- pub fn with_indexer_get(
+ pub fn with_indexer_get<
+ X: Variant + Clone,
+ const C: bool,
+ V: Variant + Clone,
+ const L: bool,
+ >(
&mut self,
- get_fn: impl RegisterNativeFunction<(Mut, X), 2, V, S> + crate::func::SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut, X), 2, C, V, L> + crate::func::SendSync + 'static,
) -> &mut Self {
self.engine.register_indexer_get(get_fn);
self
@@ -208,9 +221,16 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
///
/// Not available under both `no_index` and `no_object`.
#[inline(always)]
- pub fn with_indexer_set(
+ pub fn with_indexer_set<
+ X: Variant + Clone,
+ const C: bool,
+ V: Variant + Clone,
+ const L: bool,
+ >(
&mut self,
- set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, (), S> + crate::func::SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, C, (), L>
+ + crate::func::SendSync
+ + 'static,
) -> &mut Self {
self.engine.register_indexer_set(set_fn);
self
@@ -220,10 +240,19 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
///
/// Not available under both `no_index` and `no_object`.
#[inline(always)]
- pub fn with_indexer_get_set(
+ pub fn with_indexer_get_set<
+ X: Variant + Clone,
+ const C1: bool,
+ const C2: bool,
+ V: Variant + Clone,
+ const L1: bool,
+ const L2: bool,
+ >(
&mut self,
- get_fn: impl RegisterNativeFunction<(Mut, X), 2, V, S1> + crate::func::SendSync + 'static,
- set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, (), S2> + crate::func::SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut, X), 2, C1, V, L1> + crate::func::SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, C2, (), L2>
+ + crate::func::SendSync
+ + 'static,
) -> &mut Self {
self.engine.register_indexer_get_set(get_fn, set_fn);
self
diff --git a/src/api/deprecated.rs b/src/api/deprecated.rs
index d090d6d4..b40d936a 100644
--- a/src/api/deprecated.rs
+++ b/src/api/deprecated.rs
@@ -185,10 +185,10 @@ impl Engine {
/// This method will be removed in the next major version.
#[deprecated(since = "1.9.1", note = "use `register_fn` instead")]
#[inline(always)]
- pub fn register_result_fn(
+ pub fn register_result_fn(
&mut self,
name: impl AsRef + Into,
- func: impl RegisterNativeFunction>,
+ func: impl RegisterNativeFunction,
) -> &mut Self {
self.register_fn(name, func)
}
@@ -206,12 +206,10 @@ impl Engine {
#[deprecated(since = "1.9.1", note = "use `register_get` instead")]
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn register_get_result(
+ pub fn register_get_result(
&mut self,
name: impl AsRef,
- get_fn: impl RegisterNativeFunction<(Mut,), 1, V, RhaiResultOf>
- + crate::func::SendSync
- + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut,), 1, C, V, true> + crate::func::SendSync + 'static,
) -> &mut Self {
self.register_get(name, get_fn)
}
@@ -227,10 +225,10 @@ impl Engine {
#[deprecated(since = "1.9.1", note = "use `register_set` instead")]
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn register_set_result(
+ pub fn register_set_result(
&mut self,
name: impl AsRef,
- set_fn: impl RegisterNativeFunction<(Mut, V), 2, (), RhaiResultOf>
+ set_fn: impl RegisterNativeFunction<(Mut, V), 2, C, (), true>
+ crate::func::SendSync
+ 'static,
) -> &mut Self {
@@ -254,10 +252,10 @@ impl Engine {
T: Variant + Clone,
X: Variant + Clone,
V: Variant + Clone,
- S,
+ const C: bool,
>(
&mut self,
- get_fn: impl RegisterNativeFunction<(Mut, X), 2, V, RhaiResultOf>
+ get_fn: impl RegisterNativeFunction<(Mut, X), 2, C, V, true>
+ crate::func::SendSync
+ 'static,
) -> &mut Self {
@@ -279,10 +277,10 @@ impl Engine {
T: Variant + Clone,
X: Variant + Clone,
V: Variant + Clone,
- S,
+ const C: bool,
>(
&mut self,
- set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, (), RhaiResultOf>
+ set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, C, (), true>
+ crate::func::SendSync
+ 'static,
) -> &mut Self {
@@ -516,10 +514,15 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
/// This method will be removed in the next major version.
#[deprecated(since = "1.9.1", note = "use `with_fn` instead")]
#[inline(always)]
- pub fn with_result_fn(&mut self, name: X, method: F) -> &mut Self
+ pub fn with_result_fn(
+ &mut self,
+ name: S,
+ method: F,
+ ) -> &mut Self
where
- X: AsRef + Into,
- F: RegisterNativeFunction>,
+ S: AsRef + Into,
+ R: Variant + Clone,
+ F: RegisterNativeFunction,
{
self.with_fn(name, method)
}
@@ -538,12 +541,10 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
#[deprecated(since = "1.9.1", note = "use `with_get` instead")]
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn with_get_result(
+ pub fn with_get_result(
&mut self,
name: impl AsRef,
- get_fn: impl RegisterNativeFunction<(Mut,), 1, V, RhaiResultOf>
- + crate::func::SendSync
- + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut,), 1, C, V, true> + crate::func::SendSync + 'static,
) -> &mut Self {
self.with_get(name, get_fn)
}
@@ -560,10 +561,10 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
#[deprecated(since = "1.9.1", note = "use `with_set` instead")]
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn with_set_result(
+ pub fn with_set_result(
&mut self,
name: impl AsRef,
- set_fn: impl RegisterNativeFunction<(Mut, V), 2, (), RhaiResultOf>
+ set_fn: impl RegisterNativeFunction<(Mut, V), 2, C, (), true>
+ crate::func::SendSync
+ 'static,
) -> &mut Self {
@@ -584,9 +585,9 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
#[deprecated(since = "1.9.1", note = "use `with_indexer_get` instead")]
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
- pub fn with_indexer_get_result(
+ pub fn with_indexer_get_result(
&mut self,
- get_fn: impl RegisterNativeFunction<(Mut, X), 2, V, RhaiResultOf>
+ get_fn: impl RegisterNativeFunction<(Mut, X), 2, C, V, true>
+ crate::func::SendSync
+ 'static,
) -> &mut Self {
@@ -605,9 +606,9 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
#[deprecated(since = "1.9.1", note = "use `with_indexer_set` instead")]
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)]
- pub fn with_indexer_set_result(
+ pub fn with_indexer_set_result(
&mut self,
- set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, (), RhaiResultOf>
+ set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, C, (), true>
+ crate::func::SendSync
+ 'static,
) -> &mut Self {
diff --git a/src/api/register.rs b/src/api/register.rs
index 37a7179d..eeb50fda 100644
--- a/src/api/register.rs
+++ b/src/api/register.rs
@@ -56,7 +56,14 @@ impl Engine {
/// # }
/// ```
#[inline]
- pub fn register_fn>(
+ pub fn register_fn<
+ A,
+ const N: usize,
+ const C: bool,
+ R: Variant + Clone,
+ const L: bool,
+ F: RegisterNativeFunction,
+ >(
&mut self,
name: impl AsRef + Into,
func: F,
@@ -299,10 +306,10 @@ impl Engine {
/// ```
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn register_get(
+ pub fn register_get(
&mut self,
name: impl AsRef,
- get_fn: impl RegisterNativeFunction<(Mut,), 1, V, S> + SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut,), 1, C, V, L> + SendSync + 'static,
) -> &mut Self {
self.register_fn(crate::engine::make_getter(name.as_ref()).as_str(), get_fn)
}
@@ -349,10 +356,10 @@ impl Engine {
/// ```
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn register_set(
+ pub fn register_set(
&mut self,
name: impl AsRef,
- set_fn: impl RegisterNativeFunction<(Mut, V), 2, (), S> + SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, V), 2, C, (), L> + SendSync + 'static,
) -> &mut Self {
self.register_fn(crate::engine::make_setter(name.as_ref()).as_str(), set_fn)
}
@@ -403,11 +410,18 @@ impl Engine {
/// ```
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn register_get_set(
+ pub fn register_get_set<
+ T: Variant + Clone,
+ const C1: bool,
+ const C2: bool,
+ V: Variant + Clone,
+ const L1: bool,
+ const L2: bool,
+ >(
&mut self,
name: impl AsRef,
- get_fn: impl RegisterNativeFunction<(Mut,), 1, V, S1> + SendSync + 'static,
- set_fn: impl RegisterNativeFunction<(Mut, V), 2, (), S2> + SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut,), 1, C1, V, L1> + SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, V), 2, C2, (), L2> + SendSync + 'static,
) -> &mut Self {
self.register_get(&name, get_fn).register_set(&name, set_fn)
}
@@ -462,9 +476,15 @@ impl Engine {
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline]
- pub fn register_indexer_get(
+ pub fn register_indexer_get<
+ T: Variant + Clone,
+ X: Variant + Clone,
+ const C: bool,
+ V: Variant + Clone,
+ const L: bool,
+ >(
&mut self,
- get_fn: impl RegisterNativeFunction<(Mut, X), 2, V, S> + SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut, X), 2, C, V, L> + SendSync + 'static,
) -> &mut Self {
#[cfg(not(feature = "no_index"))]
if TypeId::of::() == TypeId::of::() {
@@ -537,9 +557,15 @@ impl Engine {
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline]
- pub fn register_indexer_set(
+ pub fn register_indexer_set<
+ T: Variant + Clone,
+ X: Variant + Clone,
+ const C: bool,
+ V: Variant + Clone,
+ const L: bool,
+ >(
&mut self,
- set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, (), S> + SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, C, (), L> + SendSync + 'static,
) -> &mut Self {
#[cfg(not(feature = "no_index"))]
if TypeId::of::() == TypeId::of::() {
@@ -616,13 +642,15 @@ impl Engine {
pub fn register_indexer_get_set<
T: Variant + Clone,
X: Variant + Clone,
+ const C1: bool,
+ const C2: bool,
V: Variant + Clone,
- S1,
- S2,
+ const L1: bool,
+ const L2: bool,
>(
&mut self,
- get_fn: impl RegisterNativeFunction<(Mut, X), 2, V, S1> + SendSync + 'static,
- set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, (), S2> + SendSync + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut, X), 2, C1, V, L1> + SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, X, V), 3, C2, (), L2> + SendSync + 'static,
) -> &mut Self {
self.register_indexer_get(get_fn)
.register_indexer_set(set_fn)
diff --git a/src/func/register.rs b/src/func/register.rs
index 0144eeba..9f31aad6 100644
--- a/src/func/register.rs
+++ b/src/func/register.rs
@@ -26,13 +26,13 @@ use std::{
///
/// # Examples
///
-/// `RegisterNativeFunction<(Mut, B, Ref), 3, R, ()>` = `Fn(&mut A, B, &C) -> R`
+/// `RegisterNativeFunction<(Mut, B, Ref), 3, false, R, false>` = `Fn(&mut A, B, &C) -> R`
///
-/// `RegisterNativeFunction<(Mut, B, Ref), 3, R, NativeCallContext>` = `Fn(NativeCallContext, &mut A, B, &C) -> R`
+/// `RegisterNativeFunction<(Mut, B, Ref), 3, true, R, false>` = `Fn(NativeCallContext, &mut A, B, &C) -> R`
///
-/// `RegisterNativeFunction<(Mut, B, Ref), 3, R, RhaiResultOf<()>>` = `Fn(&mut A, B, &C) -> Result>`
+/// `RegisterNativeFunction<(Mut, B, Ref), 3, false, R, true>` = `Fn(&mut A, B, &C) -> Result>`
///
-/// `RegisterNativeFunction<(Mut, B, Ref), 3, R, RhaiResultOf>` = `Fn(NativeCallContext, &mut A, B, &C) -> Result>`
+/// `RegisterNativeFunction<(Mut, B, Ref), 3, true, R, true>` = `Fn(NativeCallContext, &mut A, B, &C) -> Result>`
///
/// These types are not actually used anywhere.
pub struct Mut(T);
@@ -73,9 +73,10 @@ pub fn by_value(data: &mut Dynamic) -> T {
///
/// * `ARGS` - a tuple containing parameter types, with `&mut T` represented by `Mut`.
/// * `NUM` - a constant generic containing the number of parameters, must be consistent with `ARGS`.
+/// * `CTX` - a constant boolean generic indicating whether there is a `NativeCallContext` parameter.
/// * `RET` - return type of the function; if the function returns `Result`, it is the unwrapped inner value type.
-/// * `RESULT` - a type to distinguish between multiple forms. Must match the function signature.
-pub trait RegisterNativeFunction {
+/// * `FALL` - a constant boolean generic indicating whether the function is fallible (i.e. returns `Result>`).
+pub trait RegisterNativeFunction {
/// Convert this function into a [`CallableFunction`].
#[must_use]
fn into_callable_function(self) -> CallableFunction;
@@ -105,8 +106,6 @@ pub trait RegisterNativeFunction {
}
}
-const EXPECT_ARGS: &str = "arguments";
-
macro_rules! check_constant {
($abi:ident, $n:expr, $ctx:ident, $args:ident) => {
#[cfg(any(not(feature = "no_object"), not(feature = "no_index")))]
@@ -150,7 +149,7 @@ macro_rules! def_register {
FN: Fn($($param),*) -> RET + SendSync + 'static,
$($par: Variant + Clone,)*
RET: Variant + Clone
- > RegisterNativeFunction<($($mark,)*), $n, RET, ()> for FN {
+ > RegisterNativeFunction<($($mark,)*), $n, false, RET, false> for FN {
#[inline(always)] fn param_types() -> [TypeId;$n] { [$(TypeId::of::<$par>()),*] }
#[inline(always)] fn num_params() -> usize { $n }
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> [&'static str;$n] { [$(type_name::<$param>()),*] }
@@ -161,7 +160,7 @@ macro_rules! def_register {
check_constant!($abi, $n, ctx, args);
let mut drain = args.iter_mut();
- $(let mut $par = $clone(drain.next().expect(EXPECT_ARGS)); )*
+ $(let mut $par = $clone(drain.next().unwrap()); )*
// Call the function with each argument value
let r = self($($arg),*);
@@ -176,7 +175,7 @@ macro_rules! def_register {
FN: for<'a> Fn(NativeCallContext<'a>, $($param),*) -> RET + SendSync + 'static,
$($par: Variant + Clone,)*
RET: Variant + Clone
- > RegisterNativeFunction<($($mark,)*), $n, RET, NativeCallContext<'static>> for FN {
+ > RegisterNativeFunction<($($mark,)*), $n, true, RET, false> for FN {
#[inline(always)] fn param_types() -> [TypeId;$n] { [$(TypeId::of::<$par>()),*] }
#[inline(always)] fn num_params() -> usize { $n }
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> [&'static str;$n] { [$(type_name::<$param>()),*] }
@@ -187,7 +186,7 @@ macro_rules! def_register {
check_constant!($abi, $n, ctx, args);
let mut drain = args.iter_mut();
- $(let mut $par = $clone(drain.next().expect(EXPECT_ARGS)); )*
+ $(let mut $par = $clone(drain.next().unwrap()); )*
// Call the function with each argument value
let r = self(ctx, $($arg),*);
@@ -202,7 +201,7 @@ macro_rules! def_register {
FN: Fn($($param),*) -> RhaiResultOf + SendSync + 'static,
$($par: Variant + Clone,)*
RET: Variant + Clone
- > RegisterNativeFunction<($($mark,)*), $n, RET, RhaiResultOf<()>> for FN {
+ > RegisterNativeFunction<($($mark,)*), $n, false, RET, true> for FN {
#[inline(always)] fn param_types() -> [TypeId;$n] { [$(TypeId::of::<$par>()),*] }
#[inline(always)] fn num_params() -> usize { $n }
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> [&'static str;$n] { [$(type_name::<$param>()),*] }
@@ -214,7 +213,7 @@ macro_rules! def_register {
check_constant!($abi, $n, ctx, args);
let mut drain = args.iter_mut();
- $(let mut $par = $clone(drain.next().expect(EXPECT_ARGS)); )*
+ $(let mut $par = $clone(drain.next().unwrap()); )*
// Call the function with each argument value
self($($arg),*).map(Dynamic::from)
@@ -226,7 +225,7 @@ macro_rules! def_register {
FN: for<'a> Fn(NativeCallContext<'a>, $($param),*) -> RhaiResultOf + SendSync + 'static,
$($par: Variant + Clone,)*
RET: Variant + Clone
- > RegisterNativeFunction<($($mark,)*), $n, RET, RhaiResultOf>> for FN {
+ > RegisterNativeFunction<($($mark,)*), $n, true, RET, true> for FN {
#[inline(always)] fn param_types() -> [TypeId;$n] { [$(TypeId::of::<$par>()),*] }
#[inline(always)] fn num_params() -> usize { $n }
#[cfg(feature = "metadata")] #[inline(always)] fn param_names() -> [&'static str;$n] { [$(type_name::<$param>()),*] }
@@ -238,7 +237,7 @@ macro_rules! def_register {
check_constant!($abi, $n, ctx, args);
let mut drain = args.iter_mut();
- $(let mut $par = $clone(drain.next().expect(EXPECT_ARGS)); )*
+ $(let mut $par = $clone(drain.next().unwrap()); )*
// Call the function with each argument value
self(ctx, $($arg),*).map(Dynamic::from)
diff --git a/src/module/mod.rs b/src/module/mod.rs
index af70abb7..67c4038b 100644
--- a/src/module/mod.rs
+++ b/src/module/mod.rs
@@ -1237,14 +1237,14 @@ impl Module {
/// assert!(module.contains_fn(hash));
/// ```
#[inline(always)]
- pub fn set_native_fn(
+ pub fn set_native_fn(
&mut self,
name: impl AsRef + Into,
func: F,
) -> u64
where
T: Variant + Clone,
- F: RegisterNativeFunction>,
+ F: RegisterNativeFunction,
{
self.set_fn(
name,
@@ -1276,11 +1276,11 @@ impl Module {
/// ```
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn set_getter_fn(&mut self, name: impl AsRef, func: F) -> u64
+ pub fn set_getter_fn(&mut self, name: impl AsRef, func: F) -> u64
where
A: Variant + Clone,
T: Variant + Clone,
- F: RegisterNativeFunction<(Mut,), 1, T, RhaiResultOf> + SendSync + 'static,
+ F: RegisterNativeFunction<(Mut,), 1, C, T, true> + SendSync + 'static,
{
self.set_fn(
crate::engine::make_getter(name.as_ref()).as_str(),
@@ -1317,11 +1317,11 @@ impl Module {
/// ```
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn set_setter_fn(&mut self, name: impl AsRef, func: F) -> u64
+ pub fn set_setter_fn(&mut self, name: impl AsRef, func: F) -> u64
where
A: Variant + Clone,
T: Variant + Clone,
- F: RegisterNativeFunction<(Mut, T), 2, (), RhaiResultOf> + SendSync + 'static,
+ F: RegisterNativeFunction<(Mut, T), 2, C, (), true> + SendSync + 'static,
{
self.set_fn(
crate::engine::make_setter(name.as_ref()).as_str(),
@@ -1363,11 +1363,16 @@ impl Module {
/// ```
#[cfg(not(feature = "no_object"))]
#[inline(always)]
- pub fn set_getter_setter_fn(
+ pub fn set_getter_setter_fn<
+ A: Variant + Clone,
+ const C1: bool,
+ const C2: bool,
+ T: Variant + Clone,
+ >(
&mut self,
name: impl AsRef,
- getter: impl RegisterNativeFunction<(Mut,), 1, T, RhaiResultOf> + SendSync + 'static,
- setter: impl RegisterNativeFunction<(Mut, T), 2, (), RhaiResultOf> + SendSync + 'static,
+ getter: impl RegisterNativeFunction<(Mut,), 1, C1, T, true> + SendSync + 'static,
+ setter: impl RegisterNativeFunction<(Mut, T), 2, C2, (), true> + SendSync + 'static,
) -> (u64, u64) {
(
self.set_getter_fn(name.as_ref(), getter),
@@ -1404,12 +1409,12 @@ impl Module {
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline]
- pub fn set_indexer_get_fn(&mut self, func: F) -> u64
+ pub fn set_indexer_get_fn(&mut self, func: F) -> u64
where
A: Variant + Clone,
B: Variant + Clone,
T: Variant + Clone,
- F: RegisterNativeFunction<(Mut, B), 2, T, RhaiResultOf> + SendSync + 'static,
+ F: RegisterNativeFunction<(Mut, B), 2, C, T, true> + SendSync + 'static,
{
#[cfg(not(feature = "no_index"))]
if TypeId::of::() == TypeId::of::() {
@@ -1465,12 +1470,12 @@ impl Module {
/// ```
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline]
- pub fn set_indexer_set_fn(&mut self, func: F) -> u64
+ pub fn set_indexer_set_fn(&mut self, func: F) -> u64
where
A: Variant + Clone,
B: Variant + Clone,
T: Variant + Clone,
- F: RegisterNativeFunction<(Mut, B, T), 3, (), RhaiResultOf> + SendSync + 'static,
+ F: RegisterNativeFunction<(Mut, B, T), 3, C, (), true> + SendSync + 'static,
{
#[cfg(not(feature = "no_index"))]
if TypeId::of::() == TypeId::of::() {
@@ -1537,15 +1542,13 @@ impl Module {
pub fn set_indexer_get_set_fn<
A: Variant + Clone,
B: Variant + Clone,
+ const C1: bool,
+ const C2: bool,
T: Variant + Clone,
- S1,
- S2,
>(
&mut self,
- get_fn: impl RegisterNativeFunction<(Mut, B), 2, T, RhaiResultOf> + SendSync + 'static,
- set_fn: impl RegisterNativeFunction<(Mut, B, T), 3, (), RhaiResultOf>
- + SendSync
- + 'static,
+ get_fn: impl RegisterNativeFunction<(Mut, B), 2, C1, T, true> + SendSync + 'static,
+ set_fn: impl RegisterNativeFunction<(Mut, B, T), 3, C2, (), true> + SendSync + 'static,
) -> (u64, u64) {
(
self.set_indexer_get_fn(get_fn),