Struct rhai::module_resolvers::FileModuleResolver [−][src]
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
impl FileModuleResolver
[src]
pub fn new_with_path(path: impl Into<PathBuf>) -> Self
[src]
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);
pub fn new_with_path_and_extension(
path: impl Into<PathBuf>,
extension: impl Into<String>
) -> Self
[src]
path: impl Into<PathBuf>,
extension: impl Into<String>
) -> 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);
pub fn new() -> Self
[src]
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);
pub fn base_path(&self) -> &Path
[src]
Get the base path for script files.
pub fn set_base_path(&mut self, path: impl Into<PathBuf>) -> &mut SelfⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Set the base path for script files.
pub fn extension(&self) -> &str
[src]
Get the script file extension.
pub fn set_extension(&mut self, extension: impl Into<String>) -> &mut SelfⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
Set the script file extension.
pub fn is_cached(&self, path: &str) -> bool
[src]
Is a particular path cached?
pub fn clear_cache(&mut self)
[src]
Empty the internal cache.
pub fn clear_cache_for_path(&mut self, path: &str) -> Option<Shared<Module>>
[src]
Remove the specified path from internal cache.
The next time this path is resolved, the script file will be loaded once again.
Trait Implementations
impl Debug for FileModuleResolver
[src]
impl Default for FileModuleResolver
[src]
impl ModuleResolver for FileModuleResolver
[src]
fn resolve(
&self,
engine: &Engine,
path: &str,
pos: Position
) -> Result<Shared<Module>, Box<EvalAltResult>>
[src]
&self,
engine: &Engine,
path: &str,
pos: Position
) -> Result<Shared<Module>, Box<EvalAltResult>>
fn resolve_ast(
&self,
engine: &Engine,
path: &str,
pos: Position
) -> Option<Result<AST, Box<EvalAltResult>>>
[src]
&self,
engine: &Engine,
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.
Auto Trait Implementations
impl !RefUnwindSafe for FileModuleResolver
[src]
impl !Send for FileModuleResolver
[src]
impl !Sync for FileModuleResolver
[src]
impl Unpin for FileModuleResolver
[src]
impl !UnwindSafe for FileModuleResolver
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow(&self) -> &TⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut TⓘNotable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
[src]
Notable traits for &'_ mut R
impl<'_, R> Read for &'_ mut R where
R: Read + ?Sized, impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized, impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized, type Output = <F as Future>::Output;
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,