Trait AddSearcher

Source
pub trait AddSearcher {
    // Required methods
    fn add_searcher(
        &self,
        modules: HashMap<Cow<'static, str>, Cow<'static, str>>,
    ) -> Result<()>;
    fn add_path_searcher<P>(
        &self,
        modules: HashMap<Cow<'static, str>, P>,
    ) -> Result<()>
       where P: 'static + AsRef<Path> + Send;
    fn add_path_searcher_poly<P>(
        &self,
        modules: HashMap<Cow<'static, str>, P>,
        transform: Box<dyn Fn(PathBuf) -> Result<String> + Send>,
    ) -> Result<()>
       where P: 'static + AsRef<Path> + Send;
    fn add_closure_searcher(
        &self,
        modules: HashMap<Cow<'static, str>, Box<dyn for<'ctx> Fn(Context<'ctx>, Table<'ctx>, &str) -> Result<Function<'ctx>> + Send>>,
    ) -> Result<()>;
    fn add_function_searcher(
        &self,
        modules: HashMap<Cow<'static, str>, for<'ctx> fn(Context<'ctx>, Table<'ctx>, &str) -> Result<Function<'ctx>>>,
    ) -> Result<()>;
    fn add_cat_searcher(
        &self,
        modules: HashMap<Cow<'static, str>, Box<dyn Cat + Send + Sync>>,
    ) -> Result<()>;
}
Expand description

Extend rlua::Context to support requireing Lua modules by name.

Required Methods§

Source

fn add_searcher( &self, modules: HashMap<Cow<'static, str>, Cow<'static, str>>, ) -> Result<()>

Add a HashMap of Lua modules indexed by module name to Lua’s package.searchers table in an rlua::Context, with lookup functionality provided by the rlua_searcher::Searcher struct.

Source

fn add_path_searcher<P>( &self, modules: HashMap<Cow<'static, str>, P>, ) -> Result<()>
where P: 'static + AsRef<Path> + Send,

Like add_searcher, but with modules values given as paths to files containing Lua source code to facilitate module reloading.

Source

fn add_path_searcher_poly<P>( &self, modules: HashMap<Cow<'static, str>, P>, transform: Box<dyn Fn(PathBuf) -> Result<String> + Send>, ) -> Result<()>
where P: 'static + AsRef<Path> + Send,

Like add_path_searcher, but with user-provided closure for transforming source code to Lua.

Source

fn add_closure_searcher( &self, modules: HashMap<Cow<'static, str>, Box<dyn for<'ctx> Fn(Context<'ctx>, Table<'ctx>, &str) -> Result<Function<'ctx>> + Send>>, ) -> Result<()>

Like add_searcher, but with user-provided closure for rlua::Context setup.

Source

fn add_function_searcher( &self, modules: HashMap<Cow<'static, str>, for<'ctx> fn(Context<'ctx>, Table<'ctx>, &str) -> Result<Function<'ctx>>>, ) -> Result<()>

Like add_searcher, but with user-provided function for rlua::Context setup.

Source

fn add_cat_searcher( &self, modules: HashMap<Cow<'static, str>, Box<dyn Cat + Send + Sync>>, ) -> Result<()>

Like add_searcher, except modules can contain heterogenous strings and paths indexed by module name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> AddSearcher for Context<'a>

Source§

fn add_searcher( &self, modules: HashMap<Cow<'static, str>, Cow<'static, str>>, ) -> Result<()>

Source§

fn add_path_searcher<P>( &self, modules: HashMap<Cow<'static, str>, P>, ) -> Result<()>
where P: 'static + AsRef<Path> + Send,

Source§

fn add_path_searcher_poly<P>( &self, modules: HashMap<Cow<'static, str>, P>, transform: Box<dyn Fn(PathBuf) -> Result<String> + Send>, ) -> Result<()>
where P: 'static + AsRef<Path> + Send,

Source§

fn add_closure_searcher( &self, modules: HashMap<Cow<'static, str>, Box<dyn for<'ctx> Fn(Context<'ctx>, Table<'ctx>, &str) -> Result<Function<'ctx>> + Send>>, ) -> Result<()>

Source§

fn add_function_searcher( &self, modules: HashMap<Cow<'static, str>, for<'ctx> fn(Context<'ctx>, Table<'ctx>, &str) -> Result<Function<'ctx>>>, ) -> Result<()>

Source§

fn add_cat_searcher( &self, modules: HashMap<Cow<'static, str>, Box<dyn Cat + Send + Sync>>, ) -> Result<()>

Implementors§