Struct rhai::module_resolvers::FileModuleResolver
source · pub struct FileModuleResolver { /* private fields */ }
Expand description
A module resolution service that loads module script files from the file system.
§Caching
Resolved Modules are cached internally so script files are not reloaded and recompiled for subsequent requests.
Use clear_cache
or
clear_cache_for_path
to clear the internal cache.
§Namespace
When a function within a script file module is called, all functions defined within the same
script are available, evan private
ones. In other words, functions defined in a module script
can always cross-call each other.
§Example
use rhai::Engine;
use rhai::module_resolvers::FileModuleResolver;
// Create a new 'FileModuleResolver' loading scripts from the 'scripts' subdirectory
// with file extension '.x'.
let resolver = FileModuleResolver::new_with_path_and_extension("./scripts", "x");
let mut engine = Engine::new();
engine.set_module_resolver(resolver);
Implementations§
source§impl FileModuleResolver
impl FileModuleResolver
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new FileModuleResolver
with the current directory as base path.
The default extension is .rhai
.
§Example
use rhai::Engine;
use rhai::module_resolvers::FileModuleResolver;
// Create a new 'FileModuleResolver' loading scripts from the current directory
// with file extension '.rhai' (the default).
let resolver = FileModuleResolver::new();
let mut engine = Engine::new();
engine.set_module_resolver(resolver);
sourcepub fn new_with_path(path: impl Into<PathBuf>) -> Self
pub fn new_with_path(path: impl Into<PathBuf>) -> Self
Create a new FileModuleResolver
with a specific base path.
The default extension is .rhai
.
§Example
use rhai::Engine;
use rhai::module_resolvers::FileModuleResolver;
// Create a new 'FileModuleResolver' loading scripts from the 'scripts' subdirectory
// with file extension '.rhai' (the default).
let resolver = FileModuleResolver::new_with_path("./scripts");
let mut engine = Engine::new();
engine.set_module_resolver(resolver);
sourcepub fn new_with_extension(extension: impl Into<Identifier>) -> Self
pub fn new_with_extension(extension: impl Into<Identifier>) -> Self
Create a new FileModuleResolver
with a file extension.
§Example
use rhai::Engine;
use rhai::module_resolvers::FileModuleResolver;
// Create a new 'FileModuleResolver' loading scripts with file extension '.rhai' (the default).
let resolver = FileModuleResolver::new_with_extension("rhai");
let mut engine = Engine::new();
engine.set_module_resolver(resolver);
sourcepub fn new_with_path_and_extension(
path: impl Into<PathBuf>,
extension: impl Into<Identifier>
) -> Self
pub fn new_with_path_and_extension( path: impl Into<PathBuf>, extension: impl Into<Identifier> ) -> Self
Create a new FileModuleResolver
with a specific base path and file extension.
§Example
use rhai::Engine;
use rhai::module_resolvers::FileModuleResolver;
// Create a new 'FileModuleResolver' loading scripts from the 'scripts' subdirectory
// with file extension '.x'.
let resolver = FileModuleResolver::new_with_path_and_extension("./scripts", "x");
let mut engine = Engine::new();
engine.set_module_resolver(resolver);
sourcepub fn set_base_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
pub fn set_base_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
Set the base path for script files.
sourcepub fn set_extension(&mut self, extension: impl Into<Identifier>) -> &mut Self
pub fn set_extension(&mut self, extension: impl Into<Identifier>) -> &mut Self
Set the script file extension.
sourcepub fn enable_cache(&mut self, enable: bool) -> &mut Self
pub fn enable_cache(&mut self, enable: bool) -> &mut Self
Enable/disable the cache.
sourcepub const fn is_cache_enabled(&self) -> bool
pub const fn is_cache_enabled(&self) -> bool
Is the cache enabled?
sourcepub fn clear_cache(&mut self) -> &mut Self
pub fn clear_cache(&mut self) -> &mut Self
Empty the internal cache.
Trait Implementations§
source§impl Debug for FileModuleResolver
impl Debug for FileModuleResolver
source§impl Default for FileModuleResolver
impl Default for FileModuleResolver
source§impl ModuleResolver for FileModuleResolver
impl ModuleResolver for FileModuleResolver
source§fn resolve_ast(
&self,
engine: &Engine,
source_path: Option<&str>,
path: &str,
pos: Position
) -> Option<Result<AST, Box<EvalAltResult>>>
fn resolve_ast( &self, engine: &Engine, source_path: Option<&str>, path: &str, pos: Position ) -> Option<Result<AST, Box<EvalAltResult>>>
Resolve an AST
based on a path string.
The file system is accessed during each call; the internal cache is by-passed.
source§fn resolve_raw(
&self,
engine: &Engine,
global: &mut GlobalRuntimeState,
scope: &mut Scope<'_>,
path: &str,
pos: Position
) -> Result<Shared<Module>, Box<EvalAltResult>>
fn resolve_raw( &self, engine: &Engine, global: &mut GlobalRuntimeState, scope: &mut Scope<'_>, path: &str, pos: Position ) -> Result<Shared<Module>, Box<EvalAltResult>>
GlobalRuntimeState
and the current Scope
. Read more