Struct rhai::module_resolvers::FileModuleResolver[][src]

pub struct FileModuleResolver { /* fields omitted */ }

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]

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<'_, F> Future for &'_ mut F where
    F: Future + Unpin + ?Sized
type Output = <F as Future>::Output;impl<'_, I> Iterator for &'_ mut I where
    I: Iterator + ?Sized
type Item = <I as Iterator>::Item;
[src]

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<'_, F> Future for &'_ mut F where
    F: Future + Unpin + ?Sized
type Output = <F as Future>::Output;impl<'_, I> Iterator for &'_ mut I where
    I: Iterator + ?Sized
type Item = <I as Iterator>::Item;
[src]

Set the script file extension.

pub fn enable_cache(&mut self, enable: bool) -> &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<'_, F> Future for &'_ mut F where
    F: Future + Unpin + ?Sized
type Output = <F as Future>::Output;impl<'_, I> Iterator for &'_ mut I where
    I: Iterator + ?Sized
type Item = <I as Iterator>::Item;
[src]

Enable/disable the cache.

pub fn is_cache_enabled(&self) -> bool[src]

Is the cache enabled?

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_ast(
    &self,
    engine: &Engine,
    path: &str,
    pos: Position
) -> Option<Result<AST, Box<EvalAltResult>>>
[src]

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.