Skip to main content

Require

Trait Require 

Source
pub trait Require {
    // Required methods
    fn is_require_allowed(&self, chunk_name: &str) -> bool;
    fn reset(&mut self, chunk_name: &str) -> StdResult<(), NavigateError>;
    fn jump_to_alias(&mut self, path: &str) -> StdResult<(), NavigateError>;
    fn to_parent(&mut self) -> StdResult<(), NavigateError>;
    fn to_child(&mut self, name: &str) -> StdResult<(), NavigateError>;
    fn has_module(&self) -> bool;
    fn cache_key(&self) -> String;
    fn has_config(&self) -> bool;
    fn config(&self) -> IoResult<Vec<u8>>;
    fn loader(&self, lua: &Lua) -> Result<Function>;

    // Provided methods
    fn to_alias_override(
        &mut self,
        _alias: &str,
    ) -> StdResult<(), NavigateError> { ... }
    fn to_alias_fallback(
        &mut self,
        _alias: &str,
    ) -> StdResult<(), NavigateError> { ... }
}
Available on crate feature luau only.
Expand description

A trait for handling modules loading and navigation in the Luau require-by-string system.

Required Methods§

Source

fn is_require_allowed(&self, chunk_name: &str) -> bool

Returns true if “require” is permitted for the given chunk name.

Source

fn reset(&mut self, chunk_name: &str) -> StdResult<(), NavigateError>

Resets the internal state to point at the requirer module.

Source

fn jump_to_alias(&mut self, path: &str) -> StdResult<(), NavigateError>

Resets the internal state to point at an aliased module.

This function receives an exact path from a configuration file. It’s only called when an alias’s path cannot be resolved relative to its configuration file.

Source

fn to_parent(&mut self) -> StdResult<(), NavigateError>

Navigates to the parent directory of the current requirer.

Source

fn to_child(&mut self, name: &str) -> StdResult<(), NavigateError>

Navigate to the given child directory.

Source

fn has_module(&self) -> bool

Returns whether the context is currently pointing at a module.

Source

fn cache_key(&self) -> String

Provides a cache key representing the current module.

This function is only called if has_module returns true.

Source

fn has_config(&self) -> bool

Returns whether a configuration is present in the current context.

Source

fn config(&self) -> IoResult<Vec<u8>>

Returns the contents of the configuration file in the current context.

This function is only called if has_config returns true.

Source

fn loader(&self, lua: &Lua) -> Result<Function>

Returns a loader function for the current module, that when called, loads the module and returns the result.

Loader can be sync or async. This function is only called if has_module returns true.

Provided Methods§

Source

fn to_alias_override(&mut self, _alias: &str) -> StdResult<(), NavigateError>

Provides an initial alias override opportunity prior to searching for configuration files.

If Ok(()) is returned, alias resolution stops here and the internal state must point at the aliased location.

Source

fn to_alias_fallback(&mut self, _alias: &str) -> StdResult<(), NavigateError>

Provides a final opportunity to resolve an alias if it cannot be found in configuration files.

If Ok(()) is returned, alias resolution stops here and the internal state must point at the aliased location.

Trait Implementations§

Source§

impl Debug for dyn Require

Source§

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

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§