Change Option<usize> to usize for variable resolver index.

This commit is contained in:
Stephen Chung
2020-10-11 22:41:26 +08:00
parent fd5a932611
commit e343bcfa8f
8 changed files with 68 additions and 29 deletions

View File

@@ -1721,12 +1721,7 @@ impl Engine {
#[inline(always)]
pub fn on_var(
&mut self,
callback: impl Fn(
&str,
Option<usize>,
&Scope,
&EvalContext,
) -> Result<Option<Dynamic>, Box<EvalAltResult>>
callback: impl Fn(&str, usize, &Scope, &EvalContext) -> Result<Option<Dynamic>, Box<EvalAltResult>>
+ SendSync
+ 'static,
) -> &mut Self {

View File

@@ -745,7 +745,7 @@ impl Engine {
this_ptr,
level: 0,
};
if let Some(result) = resolve_var(name, index.map(|v| v.get()), scope, &context)
if let Some(result) = resolve_var(name, index.map_or(0, |v| v.get()), scope, &context)
.map_err(|err| err.fill_position(*pos))?
{
return Ok((result.into(), name, ScopeEntryType::Constant, *pos));

View File

@@ -224,13 +224,13 @@ pub type Callback<T, R> = Box<dyn Fn(&T) -> R + Send + Sync + 'static>;
/// A standard callback function.
#[cfg(not(feature = "sync"))]
pub type OnVarCallback = Box<
dyn Fn(&str, Option<usize>, &Scope, &EvalContext) -> Result<Option<Dynamic>, Box<EvalAltResult>>
dyn Fn(&str, usize, &Scope, &EvalContext) -> Result<Option<Dynamic>, Box<EvalAltResult>>
+ 'static,
>;
/// A standard callback function.
#[cfg(feature = "sync")]
pub type OnVarCallback = Box<
dyn Fn(&str, Option<usize>, &Scope, &EvalContext) -> Result<Option<Dynamic>, Box<EvalAltResult>>
dyn Fn(&str, usize, &Scope, &EvalContext) -> Result<Option<Dynamic>, Box<EvalAltResult>>
+ Send
+ Sync
+ 'static,