pub struct FileModuleResolver { /* private fields */ }rhai only.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() -> FileModuleResolver
pub fn new() -> FileModuleResolver
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>) -> FileModuleResolver
pub fn new_with_path(path: impl Into<PathBuf>) -> FileModuleResolver
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<SmartString<LazyCompact>>,
) -> FileModuleResolver
pub fn new_with_extension( extension: impl Into<SmartString<LazyCompact>>, ) -> FileModuleResolver
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<SmartString<LazyCompact>>,
) -> FileModuleResolver
pub fn new_with_path_and_extension( path: impl Into<PathBuf>, extension: impl Into<SmartString<LazyCompact>>, ) -> FileModuleResolver
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 FileModuleResolver
pub fn set_base_path( &mut self, path: impl Into<PathBuf>, ) -> &mut FileModuleResolver
Set the base path for script files.
Sourcepub fn set_extension(
&mut self,
extension: impl Into<SmartString<LazyCompact>>,
) -> &mut FileModuleResolver
pub fn set_extension( &mut self, extension: impl Into<SmartString<LazyCompact>>, ) -> &mut FileModuleResolver
Set the script file extension.
Sourcepub fn enable_cache(&mut self, enable: bool) -> &mut FileModuleResolver
pub fn enable_cache(&mut self, enable: bool) -> &mut FileModuleResolver
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 FileModuleResolver
pub fn clear_cache(&mut self) -> &mut FileModuleResolver
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§fn default() -> FileModuleResolver
fn default() -> 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<Arc<Module>, Box<EvalAltResult>>
fn resolve_raw( &self, engine: &Engine, global: &mut GlobalRuntimeState, scope: &mut Scope<'_>, path: &str, pos: Position, ) -> Result<Arc<Module>, Box<EvalAltResult>>
GlobalRuntimeState and the current Scope. Read moreAuto Trait Implementations§
impl !Freeze for FileModuleResolver
impl !RefUnwindSafe for FileModuleResolver
impl !UnwindSafe for FileModuleResolver
impl Send for FileModuleResolver
impl Sync for FileModuleResolver
impl Unpin for FileModuleResolver
impl UnsafeUnpin for FileModuleResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
follow-redirect only.