2021-08-06 08:46:30 +02:00
|
|
|
//! Module containing all deprecated API that will be removed in the next major version.
|
|
|
|
|
2022-08-22 16:16:26 +02:00
|
|
|
use crate::func::register::Mut;
|
|
|
|
use crate::func::{RegisterNativeFunction, SendSync};
|
|
|
|
use crate::types::dynamic::Variant;
|
2021-10-19 13:57:15 +02:00
|
|
|
use crate::{
|
2022-08-22 16:16:26 +02:00
|
|
|
Dynamic, Engine, EvalAltResult, FnPtr, Identifier, ImmutableString, NativeCallContext,
|
|
|
|
Position, RhaiResult, RhaiResultOf, Scope, AST,
|
2021-10-19 13:57:15 +02:00
|
|
|
};
|
2021-08-06 08:46:30 +02:00
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use std::prelude::v1::*;
|
|
|
|
|
2022-04-14 17:11:36 +02:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
|
|
|
#[cfg(not(target_family = "wasm"))]
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2021-08-06 08:46:30 +02:00
|
|
|
impl Engine {
|
|
|
|
/// Evaluate a file, but throw away the result and only return error (if any).
|
|
|
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
|
|
|
///
|
|
|
|
/// Not available under `no_std` or `WASM`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`run_file`][Engine::run_file] instead.
|
|
|
|
///
|
2022-04-14 17:11:36 +02:00
|
|
|
/// This method will be removed in the next majocd cr version.
|
2021-08-06 08:46:30 +02:00
|
|
|
#[deprecated(since = "1.1.0", note = "use `run_file` instead")]
|
|
|
|
#[cfg(not(feature = "no_std"))]
|
2022-01-12 01:12:28 +01:00
|
|
|
#[cfg(not(target_family = "wasm"))]
|
2021-08-06 08:46:30 +02:00
|
|
|
#[inline(always)]
|
2022-04-13 04:35:10 +02:00
|
|
|
pub fn consume_file(&self, path: PathBuf) -> RhaiResultOf<()> {
|
2021-08-06 08:46:30 +02:00
|
|
|
self.run_file(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Evaluate a file with own scope, but throw away the result and only return error (if any).
|
|
|
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
|
|
|
///
|
|
|
|
/// Not available under `no_std` or `WASM`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`run_file_with_scope`][Engine::run_file_with_scope] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.1.0", note = "use `run_file_with_scope` instead")]
|
|
|
|
#[cfg(not(feature = "no_std"))]
|
2022-01-12 01:12:28 +01:00
|
|
|
#[cfg(not(target_family = "wasm"))]
|
2021-08-06 08:46:30 +02:00
|
|
|
#[inline(always)]
|
2022-04-13 04:35:10 +02:00
|
|
|
pub fn consume_file_with_scope(&self, scope: &mut Scope, path: PathBuf) -> RhaiResultOf<()> {
|
2021-08-06 08:46:30 +02:00
|
|
|
self.run_file_with_scope(scope, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Evaluate a string, but throw away the result and only return error (if any).
|
|
|
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`run`][Engine::run] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.1.0", note = "use `run` instead")]
|
|
|
|
#[inline(always)]
|
2021-12-25 16:49:14 +01:00
|
|
|
pub fn consume(&self, script: &str) -> RhaiResultOf<()> {
|
2021-08-06 08:46:30 +02:00
|
|
|
self.run(script)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Evaluate a string with own scope, but throw away the result and only return error (if any).
|
|
|
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`run_with_scope`][Engine::run_with_scope] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.1.0", note = "use `run_with_scope` instead")]
|
|
|
|
#[inline(always)]
|
2021-12-25 16:49:14 +01:00
|
|
|
pub fn consume_with_scope(&self, scope: &mut Scope, script: &str) -> RhaiResultOf<()> {
|
2021-08-06 08:46:30 +02:00
|
|
|
self.run_with_scope(scope, script)
|
|
|
|
}
|
|
|
|
|
2021-11-20 14:29:36 +01:00
|
|
|
/// Evaluate an [`AST`], but throw away the result and only return error (if any).
|
2021-08-06 08:46:30 +02:00
|
|
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`run_ast`][Engine::run_ast] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.1.0", note = "use `run_ast` instead")]
|
|
|
|
#[inline(always)]
|
2021-12-25 16:49:14 +01:00
|
|
|
pub fn consume_ast(&self, ast: &AST) -> RhaiResultOf<()> {
|
2021-08-06 08:46:30 +02:00
|
|
|
self.run_ast(ast)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Evaluate an [`AST`] with own scope, but throw away the result and only return error (if any).
|
|
|
|
/// Useful for when you don't need the result, but still need to keep track of possible errors.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`run_ast_with_scope`][Engine::run_ast_with_scope] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.1.0", note = "use `run_ast_with_scope` instead")]
|
|
|
|
#[inline(always)]
|
2021-12-25 16:49:14 +01:00
|
|
|
pub fn consume_ast_with_scope(&self, scope: &mut Scope, ast: &AST) -> RhaiResultOf<()> {
|
2021-08-06 08:46:30 +02:00
|
|
|
self.run_ast_with_scope(scope, ast)
|
|
|
|
}
|
2021-11-15 04:13:00 +01:00
|
|
|
/// Call a script function defined in an [`AST`] with multiple [`Dynamic`] arguments
|
|
|
|
/// and optionally a value for binding to the `this` pointer.
|
|
|
|
///
|
|
|
|
/// Not available under `no_function`.
|
|
|
|
///
|
|
|
|
/// There is an option to evaluate the [`AST`] to load necessary modules before calling the function.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`run_ast_with_scope`][Engine::run_ast_with_scope] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
2022-08-22 16:16:26 +02:00
|
|
|
#[deprecated(since = "1.1.0", note = "use `call_fn_raw` instead")]
|
|
|
|
#[cfg(not(feature = "no_function"))]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn call_fn_dynamic(
|
|
|
|
&self,
|
|
|
|
scope: &mut Scope,
|
|
|
|
ast: &AST,
|
|
|
|
eval_ast: bool,
|
|
|
|
name: impl AsRef<str>,
|
|
|
|
this_ptr: Option<&mut Dynamic>,
|
|
|
|
arg_values: impl AsMut<[Dynamic]>,
|
|
|
|
) -> RhaiResult {
|
|
|
|
self.call_fn_raw(scope, ast, eval_ast, true, name, this_ptr, arg_values)
|
|
|
|
}
|
|
|
|
/// Register a custom fallible function with the [`Engine`].
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// # Deprecated
|
2021-11-29 06:12:47 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// This method is deprecated. Use [`register_fn`][Engine::register_fn] instead.
|
2021-11-29 06:12:47 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// 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<N, A, F, R, S>(&mut self, name: N, func: F) -> &mut Self
|
|
|
|
where
|
|
|
|
N: AsRef<str> + Into<Identifier>,
|
|
|
|
F: RegisterNativeFunction<A, R, RhaiResultOf<S>>,
|
|
|
|
{
|
|
|
|
self.register_fn(name, func)
|
|
|
|
}
|
|
|
|
/// Register a getter function for a member of a registered type with the [`Engine`].
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// The function signature must start with `&mut self` and not `&self`.
|
2021-12-27 04:43:11 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// Not available under `no_object`.
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// # Deprecated
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// This method is deprecated. Use [`register_get`][Engine::register_get] instead.
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `register_get` instead")]
|
|
|
|
#[cfg(not(feature = "no_object"))]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn register_get_result<T: Variant + Clone, V: Variant + Clone, S>(
|
|
|
|
&mut self,
|
|
|
|
name: impl AsRef<str>,
|
|
|
|
get_fn: impl RegisterNativeFunction<(Mut<T>,), V, RhaiResultOf<S>> + SendSync + 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.register_get(name, get_fn)
|
|
|
|
}
|
|
|
|
/// Register a setter function for a member of a registered type with the [`Engine`].
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// Not available under `no_object`.
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// # Deprecated
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// This method is deprecated. Use [`register_set`][Engine::register_set] instead.
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `register_set` instead")]
|
|
|
|
#[cfg(not(feature = "no_object"))]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn register_set_result<T: Variant + Clone, V: Variant + Clone, S>(
|
|
|
|
&mut self,
|
|
|
|
name: impl AsRef<str>,
|
|
|
|
set_fn: impl RegisterNativeFunction<(Mut<T>, V), (), RhaiResultOf<S>> + SendSync + 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.register_set(name, set_fn)
|
|
|
|
}
|
|
|
|
/// Register an index getter for a custom type with the [`Engine`].
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// The function signature must start with `&mut self` and not `&self`.
|
2021-11-15 04:13:00 +01:00
|
|
|
///
|
2022-08-22 16:16:26 +02:00
|
|
|
/// Not available under both `no_index` and `no_object`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`register_indexer_get`][Engine::register_indexer_get] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// Panics if the type is [`Array`][crate::Array], [`Map`][crate::Map], [`String`],
|
|
|
|
/// [`ImmutableString`][crate::ImmutableString], `&str` or [`INT`][crate::INT].
|
|
|
|
/// Indexers for arrays, object maps, strings and integers cannot be registered.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `register_indexer_get` instead")]
|
|
|
|
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
2021-11-15 04:13:00 +01:00
|
|
|
#[inline(always)]
|
2022-08-22 16:16:26 +02:00
|
|
|
pub fn register_indexer_get_result<
|
|
|
|
T: Variant + Clone,
|
|
|
|
X: Variant + Clone,
|
|
|
|
V: Variant + Clone,
|
|
|
|
S,
|
|
|
|
>(
|
|
|
|
&mut self,
|
|
|
|
get_fn: impl RegisterNativeFunction<(Mut<T>, X), V, RhaiResultOf<S>> + SendSync + 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.register_indexer_get(get_fn)
|
|
|
|
}
|
|
|
|
/// Register an index setter for a custom type with the [`Engine`].
|
|
|
|
///
|
|
|
|
/// Not available under both `no_index` and `no_object`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`register_indexer_set`][Engine::register_indexer_set] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// Panics if the type is [`Array`][crate::Array], [`Map`][crate::Map], [`String`],
|
|
|
|
/// [`ImmutableString`][crate::ImmutableString], `&str` or [`INT`][crate::INT].
|
|
|
|
/// Indexers for arrays, object maps, strings and integers cannot be registered.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `register_indexer_set` instead")]
|
|
|
|
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn register_indexer_set_result<
|
|
|
|
T: Variant + Clone,
|
|
|
|
X: Variant + Clone,
|
|
|
|
V: Variant + Clone,
|
|
|
|
S,
|
|
|
|
>(
|
|
|
|
&mut self,
|
|
|
|
set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), (), RhaiResultOf<S>> + SendSync + 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.register_indexer_set(set_fn)
|
2021-11-15 04:13:00 +01:00
|
|
|
}
|
2021-08-06 08:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Dynamic {
|
|
|
|
/// Convert the [`Dynamic`] into a [`String`] and return it.
|
|
|
|
/// If there are other references to the same string, a cloned copy is returned.
|
|
|
|
/// Returns the name of the actual type if the cast fails.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`into_string`][Dynamic::into_string] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.1.0", note = "use `into_string` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn as_string(self) -> Result<String, &'static str> {
|
|
|
|
self.into_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Convert the [`Dynamic`] into an [`ImmutableString`] and return it.
|
|
|
|
/// Returns the name of the actual type if the cast fails.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`into_immutable_string`][Dynamic::into_immutable_string] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.1.0", note = "use `into_immutable_string` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn as_immutable_string(self) -> Result<ImmutableString, &'static str> {
|
|
|
|
self.into_immutable_string()
|
|
|
|
}
|
|
|
|
}
|
2021-10-19 13:57:15 +02:00
|
|
|
|
|
|
|
impl NativeCallContext<'_> {
|
|
|
|
/// Call a function inside the call context.
|
|
|
|
///
|
2021-11-28 15:57:28 +01:00
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`call_fn_raw`][NativeCallContext::call_fn_raw] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
2021-10-19 13:57:15 +02:00
|
|
|
#[deprecated(since = "1.2.0", note = "use `call_fn_raw` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn call_fn_dynamic_raw(
|
|
|
|
&self,
|
|
|
|
fn_name: impl AsRef<str>,
|
|
|
|
is_method_call: bool,
|
|
|
|
args: &mut [&mut Dynamic],
|
|
|
|
) -> RhaiResult {
|
|
|
|
self.call_fn_raw(fn_name.as_ref(), is_method_call, is_method_call, args)
|
|
|
|
}
|
|
|
|
}
|
2021-10-19 17:52:58 +02:00
|
|
|
|
|
|
|
#[allow(useless_deprecated)]
|
|
|
|
#[deprecated(since = "1.2.0", note = "explicitly wrap `EvalAltResult` in `Err`")]
|
2021-12-25 16:49:14 +01:00
|
|
|
impl<T> From<EvalAltResult> for RhaiResultOf<T> {
|
2021-10-19 17:52:58 +02:00
|
|
|
#[inline(always)]
|
|
|
|
fn from(err: EvalAltResult) -> Self {
|
|
|
|
Err(err.into())
|
|
|
|
}
|
|
|
|
}
|
2021-11-29 05:43:59 +01:00
|
|
|
|
|
|
|
impl FnPtr {
|
2022-05-05 16:30:55 +02:00
|
|
|
/// Get the number of curried arguments.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`curry().len()`][`FnPtr::curry`] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.8.0", note = "use `curry().len()` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
#[must_use]
|
|
|
|
pub fn num_curried(&self) -> usize {
|
|
|
|
self.curry().len()
|
|
|
|
}
|
2021-11-29 05:43:59 +01:00
|
|
|
/// Call the function pointer with curried arguments (if any).
|
|
|
|
/// The function may be script-defined (not available under `no_function`) or native Rust.
|
|
|
|
///
|
|
|
|
/// This method is intended for calling a function pointer that is passed into a native Rust
|
|
|
|
/// function as an argument. Therefore, the [`AST`] is _NOT_ evaluated before calling the
|
|
|
|
/// function.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use [`call_within_context`][FnPtr::call_within_context] or
|
|
|
|
/// [`call_raw`][FnPtr::call_raw] instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(
|
|
|
|
since = "1.3.0",
|
|
|
|
note = "use `call_within_context` or `call_raw` instead"
|
|
|
|
)]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn call_dynamic(
|
|
|
|
&self,
|
|
|
|
context: &NativeCallContext,
|
|
|
|
this_ptr: Option<&mut Dynamic>,
|
|
|
|
arg_values: impl AsMut<[Dynamic]>,
|
|
|
|
) -> RhaiResult {
|
|
|
|
self.call_raw(context, this_ptr, arg_values)
|
|
|
|
}
|
|
|
|
}
|
2021-12-16 11:01:49 +01:00
|
|
|
|
2022-07-05 16:59:03 +02:00
|
|
|
#[cfg(not(feature = "no_custom_syntax"))]
|
|
|
|
impl crate::Expression<'_> {
|
2021-12-16 11:01:49 +01:00
|
|
|
/// If this expression is a variable name, return it. Otherwise [`None`].
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
2022-07-18 17:01:03 +02:00
|
|
|
/// This method is deprecated. Use [`get_string_value`][crate::Expression::get_string_value] instead.
|
2021-12-16 11:01:49 +01:00
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.4.0", note = "use `get_string_value` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
#[must_use]
|
|
|
|
pub fn get_variable_name(&self) -> Option<&str> {
|
|
|
|
self.get_string_value()
|
|
|
|
}
|
|
|
|
}
|
2022-02-24 02:08:10 +01:00
|
|
|
|
|
|
|
impl Position {
|
|
|
|
/// Create a new [`Position`].
|
|
|
|
///
|
|
|
|
/// If `line` is zero, then [`None`] is returned.
|
|
|
|
///
|
|
|
|
/// If `position` is zero, then it is at the beginning of a line.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This function is deprecated. Use [`new`][Position::new] (which panics when `line` is zero) instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.6.0", note = "use `new` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
#[must_use]
|
|
|
|
pub const fn new_const(line: u16, position: u16) -> Option<Self> {
|
|
|
|
if line == 0 {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(Self::new(line, position))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-22 16:16:26 +02:00
|
|
|
|
|
|
|
#[allow(deprecated)]
|
|
|
|
impl<'a, T: Variant + Clone> crate::TypeBuilder<'a, T> {
|
|
|
|
/// Register a custom fallible function.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use `with_fn` instead.
|
|
|
|
///
|
|
|
|
/// 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<N, A, F, R, S>(&mut self, name: N, method: F) -> &mut Self
|
|
|
|
where
|
|
|
|
N: AsRef<str> + Into<Identifier>,
|
|
|
|
F: RegisterNativeFunction<A, R, RhaiResultOf<S>>,
|
|
|
|
{
|
|
|
|
self.with_fn(name, method)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Register a fallible getter function.
|
|
|
|
///
|
|
|
|
/// The function signature must start with `&mut self` and not `&self`.
|
|
|
|
///
|
|
|
|
/// Not available under `no_object`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use `with_get` instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `with_get` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn with_get_result<V: Variant + Clone, S>(
|
|
|
|
&mut self,
|
|
|
|
name: impl AsRef<str>,
|
|
|
|
get_fn: impl RegisterNativeFunction<(Mut<T>,), V, RhaiResultOf<S>>
|
|
|
|
+ crate::func::SendSync
|
|
|
|
+ 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.with_get(name, get_fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Register a fallible setter function.
|
|
|
|
///
|
|
|
|
/// Not available under `no_object`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use `with_set` instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `with_set` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn with_set_result<V: Variant + Clone, S>(
|
|
|
|
&mut self,
|
|
|
|
name: impl AsRef<str>,
|
|
|
|
set_fn: impl RegisterNativeFunction<(Mut<T>, V), (), RhaiResultOf<S>>
|
|
|
|
+ crate::func::SendSync
|
|
|
|
+ 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.with_set(name, set_fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Register an fallible index getter.
|
|
|
|
///
|
|
|
|
/// The function signature must start with `&mut self` and not `&self`.
|
|
|
|
///
|
|
|
|
/// Not available under both `no_index` and `no_object`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use `with_indexer_get` instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `with_indexer_get` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn with_indexer_get_result<X: Variant + Clone, V: Variant + Clone, S>(
|
|
|
|
&mut self,
|
|
|
|
get_fn: impl RegisterNativeFunction<(Mut<T>, X), V, RhaiResultOf<S>>
|
|
|
|
+ crate::func::SendSync
|
|
|
|
+ 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.with_indexer_get(get_fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Register an fallible index setter.
|
|
|
|
///
|
|
|
|
/// Not available under both `no_index` and `no_object`.
|
|
|
|
///
|
|
|
|
/// # Deprecated
|
|
|
|
///
|
|
|
|
/// This method is deprecated. Use `with_indexer_set` instead.
|
|
|
|
///
|
|
|
|
/// This method will be removed in the next major version.
|
|
|
|
#[deprecated(since = "1.9.1", note = "use `with_indexer_set` instead")]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn with_indexer_set_result<X: Variant + Clone, V: Variant + Clone, S>(
|
|
|
|
&mut self,
|
|
|
|
set_fn: impl RegisterNativeFunction<(Mut<T>, X, V), (), RhaiResultOf<S>>
|
|
|
|
+ crate::func::SendSync
|
|
|
|
+ 'static,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.with_indexer_set(set_fn)
|
|
|
|
}
|
|
|
|
}
|