clean up ClosureSearcher api with hrtb
see - https://stackoverflow.com/questions/35592750/how-does-for-syntax-differ-from-a-regular-lifetime-bound/35595491#35595491 - https://doc.rust-lang.org/nomicon/hrtb.html
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use rlua::{Context, Lua, Table, UserData, UserDataMethods, Value};
|
||||
use rlua::{Context, Function, Lua, Table, UserData, UserDataMethods, Value};
|
||||
use rlua_searcher::{AddSearcher, Result};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
@@ -166,10 +166,15 @@ fn add_closure_searcher_works() {
|
||||
|
||||
let mut modules: HashMap<
|
||||
&'static str,
|
||||
Box<dyn Fn(Context) -> rlua::Result<&'static str> + Send>,
|
||||
Box<
|
||||
dyn for<'ctx> Fn(Context<'ctx>, Table<'ctx>, &str) -> rlua::Result<Function<'ctx>>
|
||||
+ Send,
|
||||
>,
|
||||
> = HashMap::new();
|
||||
|
||||
let instrument_loader = Box::new(|lua_ctx: Context| {
|
||||
let instrument_loader: Box<
|
||||
dyn for<'ctx> Fn(Context<'ctx>, Table<'ctx>, &str) -> rlua::Result<Function<'ctx>> + Send,
|
||||
> = Box::new(|lua_ctx, env, name| {
|
||||
let globals = lua_ctx.globals();
|
||||
let new = lua_ctx.create_function(|_, (name, sound): (String, String)| {
|
||||
Ok(Instrument::new(name, sound))
|
||||
@@ -177,7 +182,11 @@ fn add_closure_searcher_works() {
|
||||
let tbl = lua_ctx.create_table()?;
|
||||
tbl.set("new", new)?;
|
||||
globals.set("instrument", tbl)?;
|
||||
Ok("return instrument")
|
||||
Ok(lua_ctx
|
||||
.load("return instrument")
|
||||
.set_name(name)?
|
||||
.set_environment(env)?
|
||||
.into_function()?)
|
||||
});
|
||||
|
||||
modules.insert("instrument", instrument_loader);
|
||||
|
Reference in New Issue
Block a user