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

pub struct FileModuleResolver { /* fields omitted */ }
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

impl FileModuleResolver[src]

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 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_extension(extension: impl Into<Identifier>) -> Self[src]

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);

pub fn new_with_path_and_extension(
    path: impl Into<PathBuf>,
    extension: impl Into<Identifier>
) -> 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 base_path(&self) -> Option<&Path>[src]

Get the base path for script files.

pub fn set_base_path(&mut self, path: impl Into<PathBuf>) -> &mut Self[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<Identifier>) -> &mut Self[src]

Set the script file extension.

pub fn enable_cache(&mut self, enable: bool) -> &mut Self[src]

Enable/disable the cache.

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

Is the cache enabled?

pub fn is_cached(&self, path: &str, source_path: Option<&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,
    source_path: Option<&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]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Default for FileModuleResolver[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

impl ModuleResolver for FileModuleResolver[src]

fn resolve_ast(
    &self,
    engine: &Engine,
    source_path: Option<&str>,
    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.

fn resolve(
    &self,
    engine: &Engine,
    source_path: Option<&str>,
    path: &str,
    pos: Position
) -> Result<Shared<Module>, Box<EvalAltResult>>
[src]

Resolve a module based on a path string.

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.