Use macro auto_restore!.
This commit is contained in:
@@ -117,7 +117,7 @@ impl<'a, T: Variant + Clone> TypeBuilder<'a, T> {
|
||||
|
||||
/// Register a custom function.
|
||||
#[inline(always)]
|
||||
pub fn with_fn<A, const N: usize, const C: bool, R: Variant + Clone, const L: bool>(
|
||||
pub fn with_fn<A: 'static, const N: usize, const C: bool, R: Variant + Clone, const L: bool>(
|
||||
&mut self,
|
||||
name: impl AsRef<str> + Into<Identifier>,
|
||||
method: impl RegisterNativeFunction<A, N, C, R, L>,
|
||||
|
@@ -3,10 +3,8 @@
|
||||
|
||||
use crate::eval::{Caches, GlobalRuntimeState};
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::types::RestoreOnDrop;
|
||||
use crate::{
|
||||
reify, Dynamic, Engine, FuncArgs, Position, RhaiResult, RhaiResultOf, Scope, StaticVec, AST,
|
||||
ERR,
|
||||
Dynamic, Engine, FuncArgs, Position, RhaiResult, RhaiResultOf, Scope, StaticVec, AST, ERR,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@@ -241,9 +239,7 @@ impl Engine {
|
||||
|
||||
let result = if options.eval_ast && !statements.is_empty() {
|
||||
let orig_scope_len = scope.len();
|
||||
let scope = &mut *RestoreOnDrop::lock_if(rewind_scope, scope, move |s| {
|
||||
s.rewind(orig_scope_len);
|
||||
});
|
||||
auto_restore!(scope; rewind_scope => move |s| { s.rewind(orig_scope_len); });
|
||||
|
||||
self.eval_global_statements(global, caches, scope, statements)
|
||||
} else {
|
||||
|
@@ -7,8 +7,8 @@ use crate::parser::ParseResult;
|
||||
use crate::tokenizer::{is_valid_identifier, Token, NO_TOKEN};
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::{
|
||||
reify, Dynamic, Engine, EvalContext, Identifier, ImmutableString, LexError, Position,
|
||||
RhaiResult, StaticVec,
|
||||
Dynamic, Engine, EvalContext, Identifier, ImmutableString, LexError, Position, RhaiResult,
|
||||
StaticVec,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
@@ -185,7 +185,7 @@ 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<A, const N: usize, const C: bool, R: Variant + Clone>(
|
||||
pub fn register_result_fn<A: 'static, const N: usize, const C: bool, R: Variant + Clone>(
|
||||
&mut self,
|
||||
name: impl AsRef<str> + Into<Identifier>,
|
||||
func: impl RegisterNativeFunction<A, N, C, R, true>,
|
||||
@@ -514,7 +514,7 @@ 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<S, A, const N: usize, const C: bool, R, F>(
|
||||
pub fn with_result_fn<S, A: 'static, const N: usize, const C: bool, R, F>(
|
||||
&mut self,
|
||||
name: S,
|
||||
method: F,
|
||||
|
@@ -5,7 +5,7 @@ use crate::func::native::locked_write;
|
||||
use crate::parser::ParseState;
|
||||
use crate::types::dynamic::Variant;
|
||||
use crate::{
|
||||
reify, Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR,
|
||||
Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
@@ -57,7 +57,7 @@ impl Engine {
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn register_fn<
|
||||
A,
|
||||
A: 'static,
|
||||
const N: usize,
|
||||
const C: bool,
|
||||
R: Variant + Clone,
|
||||
|
Reference in New Issue
Block a user