Minor housekeeping.

This commit is contained in:
Stephen Chung
2022-02-24 10:36:20 +08:00
parent 2f5ce2fe5b
commit 73f10b8adc
15 changed files with 128 additions and 135 deletions

View File

@@ -77,8 +77,8 @@ impl Engine {
.into()
})
}
/// Call a script function defined in an [`AST`] with multiple [`Dynamic`] arguments
/// and the following options:
/// Call a script function defined in an [`AST`] with multiple [`Dynamic`] arguments and the
/// following options:
///
/// * whether to evaluate the [`AST`] to load necessary modules before calling the function
/// * whether to rewind the [`Scope`] after the function call
@@ -95,8 +95,8 @@ impl Engine {
/// All the arguments are _consumed_, meaning that they're replaced by `()`.
/// This is to avoid unnecessarily cloning the arguments.
///
/// Do not use the arguments after this call. If they are needed afterwards,
/// clone them _before_ calling this function.
/// Do not use the arguments after this call. If they are needed afterwards, clone them _before_
/// calling this function.
///
/// # Example
///

View File

@@ -85,6 +85,7 @@ impl Expression<'_> {
self.0.position()
}
/// Get the value of this expression if it is a literal constant.
///
/// Supports [`INT`][crate::INT], [`FLOAT`][crate::FLOAT], `()`, `char`, `bool` and
/// [`ImmutableString`][crate::ImmutableString].
///

View File

@@ -34,8 +34,9 @@ impl Engine {
/// ## Constants Propagation
///
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
/// the scope are propagated throughout the script _including_ functions. This allows functions
/// to be optimized based on dynamic global constants.
/// the scope are propagated throughout the script _including_ functions.
///
/// This allows functions to be optimized based on dynamic global constants.
///
/// # Example
///

View File

@@ -72,8 +72,9 @@ impl Engine {
/// ## Constants Propagation
///
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
/// the scope are propagated throughout the script _including_ functions. This allows functions
/// to be optimized based on dynamic global constants.
/// the scope are propagated throughout the script _including_ functions.
///
/// This allows functions to be optimized based on dynamic global constants.
///
/// # Example
///
@@ -134,8 +135,9 @@ impl Engine {
/// ## Constants Propagation
///
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
/// the scope are propagated throughout the script _including_ functions. This allows functions
/// to be optimized based on dynamic global constants.
/// the scope are propagated throughout the script _including_ functions.
///
/// This allows functions to be optimized based on dynamic global constants.
///
/// # Example
///
@@ -176,8 +178,9 @@ impl Engine {
/// ## Constants Propagation
///
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
/// the scope are propagated throughout the script _including_ functions. This allows functions
/// to be optimized based on dynamic global constants.
/// the scope are propagated throughout the script _including_ functions.
///
/// This allows functions to be optimized based on dynamic global constants.
#[inline]
pub fn run_file_with_scope(
&self,

View File

@@ -82,21 +82,26 @@ impl Engine {
pub const fn optimization_level(&self) -> crate::OptimizationLevel {
self.optimization_level
}
/// Optimize the [`AST`][crate::AST] with constants defined in an external Scope. An optimized
/// copy of the [`AST`][crate::AST] is returned while the original [`AST`][crate::AST] is consumed.
/// Optimize the [`AST`][crate::AST] with constants defined in an external Scope.
/// An optimized copy of the [`AST`][crate::AST] is returned while the original [`AST`][crate::AST]
/// is consumed.
///
/// Not available under `no_optimize`.
///
/// Although optimization is performed by default during compilation, sometimes it is necessary
/// to _re_-optimize an [`AST`][crate::AST]. For example, when working with constants that are
/// passed in via an external scope, it will be more efficient to optimize the
/// [`AST`][crate::AST] once again to take advantage of the new constants.
/// to _re_-optimize an [`AST`][crate::AST].
///
/// For example, when working with constants that are passed in via an external scope, it will
/// be more efficient to optimize the [`AST`][crate::AST] once again to take advantage of the
/// new constants.
///
/// With this method, it is no longer necessary to recompile a large script. The script
/// [`AST`][crate::AST] can be compiled just once. Before evaluation, constants are passed into
/// the [`Engine`] via an external scope (i.e. with
/// [`Scope::push_constant`][crate::Scope::push_constant]). Then, the [`AST`][crate::AST] is
/// cloned and the copy re-optimized before running.
/// [`AST`][crate::AST] can be compiled just once.
///
/// Before evaluation, constants are passed into the [`Engine`] via an external scope (i.e. with
/// [`Scope::push_constant`][crate::Scope::push_constant]).
///
/// Then, the [`AST`][crate::AST] is cloned and the copy re-optimized before running.
#[inline]
#[must_use]
pub fn optimize_ast(
@@ -148,8 +153,8 @@ impl Engine {
///
/// # Examples
///
/// The following will raise an error during parsing because the `if` keyword is disabled
/// and is recognized as a reserved symbol!
/// The following will raise an error during parsing because the `if` keyword is disabled and is
/// recognized as a reserved symbol!
///
/// ```rust,should_panic
/// # fn main() -> Result<(), rhai::ParseError> {

View File

@@ -57,7 +57,7 @@ impl Engine {
/// Is `if`-expression allowed?
/// Default is `true`.
#[inline(always)]
pub fn allow_if_expression(&self) -> bool {
pub const fn allow_if_expression(&self) -> bool {
self.options.allow_if_expr
}
/// Set whether `if`-expression is allowed.
@@ -68,7 +68,7 @@ impl Engine {
/// Is `switch` expression allowed?
/// Default is `true`.
#[inline(always)]
pub fn allow_switch_expression(&self) -> bool {
pub const fn allow_switch_expression(&self) -> bool {
self.options.allow_switch_expr
}
/// Set whether `switch` expression is allowed.
@@ -79,7 +79,7 @@ impl Engine {
/// Is statement-expression allowed?
/// Default is `true`.
#[inline(always)]
pub fn allow_statement_expression(&self) -> bool {
pub const fn allow_statement_expression(&self) -> bool {
self.options.allow_stmt_expr
}
/// Set whether statement-expression is allowed.
@@ -93,7 +93,7 @@ impl Engine {
/// Not available under `no_function`.
#[cfg(not(feature = "no_function"))]
#[inline(always)]
pub fn allow_anonymous_fn(&self) -> bool {
pub const fn allow_anonymous_fn(&self) -> bool {
self.options.allow_anonymous_fn
}
/// Set whether anonymous function is allowed.
@@ -107,7 +107,7 @@ impl Engine {
/// Is looping allowed?
/// Default is `true`.
#[inline(always)]
pub fn allow_looping(&self) -> bool {
pub const fn allow_looping(&self) -> bool {
self.options.allow_looping
}
/// Set whether looping is allowed.
@@ -118,7 +118,7 @@ impl Engine {
/// Is variables shadowing allowed?
/// Default is `true`.
#[inline(always)]
pub fn allow_shadowing(&self) -> bool {
pub const fn allow_shadowing(&self) -> bool {
self.options.allow_shadowing
}
/// Set whether variables shadowing is allowed.
@@ -129,7 +129,7 @@ impl Engine {
/// Is strict variables mode enabled?
/// Default is `false`.
#[inline(always)]
pub fn strict_variables(&self) -> bool {
pub const fn strict_variables(&self) -> bool {
self.options.strict_var
}
/// Set whether strict variables mode is enabled.
@@ -143,7 +143,7 @@ impl Engine {
/// Not available under `no_object`.
#[cfg(not(feature = "no_object"))]
#[inline(always)]
pub fn fail_on_invalid_map_property(&self) -> bool {
pub const fn fail_on_invalid_map_property(&self) -> bool {
self.options.fail_on_invalid_map_property
}
/// Set whether to raise error if an object map property does not exist.