Make more functions const.
This commit is contained in:
parent
bd35999b75
commit
fc349f67f8
@ -127,7 +127,7 @@ impl Expression<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EvalContext<'_, '_, '_, '_, '_, '_, '_> {
|
impl EvalContext<'_, '_, '_, '_, '_, '_, '_, '_> {
|
||||||
/// Evaluate an [expression tree][Expression].
|
/// Evaluate an [expression tree][Expression].
|
||||||
///
|
///
|
||||||
/// # WARNING - Low Level API
|
/// # WARNING - Low Level API
|
||||||
|
@ -740,21 +740,21 @@ impl Default for Limits {
|
|||||||
|
|
||||||
/// Context of a script evaluation process.
|
/// Context of a script evaluation process.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EvalContext<'a, 'x, 'px, 'm, 's, 't, 'pt> {
|
pub struct EvalContext<'a, 'x, 'px, 'm, 's, 'b, 't, 'pt> {
|
||||||
pub(crate) engine: &'a Engine,
|
pub(crate) engine: &'a Engine,
|
||||||
pub(crate) scope: &'x mut Scope<'px>,
|
pub(crate) scope: &'x mut Scope<'px>,
|
||||||
pub(crate) mods: &'m mut Imports,
|
pub(crate) mods: &'m mut Imports,
|
||||||
pub(crate) state: &'s mut State,
|
pub(crate) state: &'s mut State,
|
||||||
pub(crate) lib: &'a [&'a Module],
|
pub(crate) lib: &'b [&'b Module],
|
||||||
pub(crate) this_ptr: &'t mut Option<&'pt mut Dynamic>,
|
pub(crate) this_ptr: &'t mut Option<&'pt mut Dynamic>,
|
||||||
pub(crate) level: usize,
|
pub(crate) level: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'x, 'px> EvalContext<'_, 'x, 'px, '_, '_, '_, '_> {
|
impl<'x, 'px> EvalContext<'_, 'x, 'px, '_, '_, '_, '_, '_> {
|
||||||
/// The current [`Engine`].
|
/// The current [`Engine`].
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn engine(&self) -> &Engine {
|
pub const fn engine(&self) -> &Engine {
|
||||||
self.engine
|
self.engine
|
||||||
}
|
}
|
||||||
/// The current source.
|
/// The current source.
|
||||||
@ -766,7 +766,7 @@ impl<'x, 'px> EvalContext<'_, 'x, 'px, '_, '_, '_, '_> {
|
|||||||
/// The current [`Scope`].
|
/// The current [`Scope`].
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn scope(&self) -> &Scope {
|
pub const fn scope(&self) -> &Scope<'px> {
|
||||||
self.scope
|
self.scope
|
||||||
}
|
}
|
||||||
/// Mutable reference to the current [`Scope`].
|
/// Mutable reference to the current [`Scope`].
|
||||||
@ -788,7 +788,7 @@ impl<'x, 'px> EvalContext<'_, 'x, 'px, '_, '_, '_, '_> {
|
|||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn imports(&self) -> &Imports {
|
pub const fn imports(&self) -> &Imports {
|
||||||
self.mods
|
self.mods
|
||||||
}
|
}
|
||||||
/// Get an iterator over the namespaces containing definition of all script-defined functions.
|
/// Get an iterator over the namespaces containing definition of all script-defined functions.
|
||||||
@ -802,7 +802,7 @@ impl<'x, 'px> EvalContext<'_, 'x, 'px, '_, '_, '_, '_> {
|
|||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn namespaces(&self) -> &[&Module] {
|
pub const fn namespaces(&self) -> &[&Module] {
|
||||||
self.lib
|
self.lib
|
||||||
}
|
}
|
||||||
/// The current bound `this` pointer, if any.
|
/// The current bound `this` pointer, if any.
|
||||||
@ -814,7 +814,7 @@ impl<'x, 'px> EvalContext<'_, 'x, 'px, '_, '_, '_, '_> {
|
|||||||
/// The current nesting level of function calls.
|
/// The current nesting level of function calls.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn call_level(&self) -> usize {
|
pub const fn call_level(&self) -> usize {
|
||||||
self.level
|
self.level
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ impl Engine {
|
|||||||
#[cfg(not(feature = "no_optimize"))]
|
#[cfg(not(feature = "no_optimize"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn optimization_level(&self) -> crate::OptimizationLevel {
|
pub const fn optimization_level(&self) -> crate::OptimizationLevel {
|
||||||
self.optimization_level
|
self.optimization_level
|
||||||
}
|
}
|
||||||
/// Set the maximum levels of function calls allowed for a script in order to avoid
|
/// Set the maximum levels of function calls allowed for a script in order to avoid
|
||||||
@ -179,7 +179,7 @@ impl Engine {
|
|||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn max_array_size(&self) -> usize {
|
pub const fn max_array_size(&self) -> usize {
|
||||||
if let Some(n) = self.limits.max_array_size {
|
if let Some(n) = self.limits.max_array_size {
|
||||||
n.get()
|
n.get()
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,7 +68,7 @@ impl<'a> State<'a> {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
changed: false,
|
changed: false,
|
||||||
variables: vec![],
|
variables: Vec::new(),
|
||||||
propagate_constants: true,
|
propagate_constants: true,
|
||||||
engine,
|
engine,
|
||||||
lib,
|
lib,
|
||||||
|
@ -143,7 +143,7 @@ impl<'e> ParseState<'e> {
|
|||||||
///
|
///
|
||||||
/// Return `None` when the variable name is not found in the `stack`.
|
/// Return `None` when the variable name is not found in the `stack`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn access_var(&mut self, name: &str, _pos: Position) -> Option<NonZeroUsize> {
|
pub fn access_var(&mut self, name: &str, _pos: Position) -> Option<NonZeroUsize> {
|
||||||
let mut barrier = false;
|
let mut barrier = false;
|
||||||
|
|
||||||
let index = self
|
let index = self
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use rhai::{Dynamic, Engine, EvalAltResult, LexError, ParseError, ParseErrorType, Position, INT};
|
use rhai::{Dynamic, Engine, EvalAltResult, LexError, ParseErrorType, Position, INT};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
|
fn test_custom_syntax() -> Result<(), Box<EvalAltResult>> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user