index StaticSearcher &'static str by &'static str
credit - https://stackoverflow.com/questions/65549983/trait-borrowstring-is-not-implemented-for-str/65550108#65550108
This commit is contained in:
parent
f159a7cc27
commit
4aa2f52dd7
@ -43,12 +43,12 @@ impl UserData for Searcher {
|
||||
/// Like `Searcher`, but with `modules` values encoded as `&'static str`
|
||||
/// to facilitate compile-time includes of Fennel source code.
|
||||
struct StaticSearcher {
|
||||
modules: HashMap<String, &'static str>,
|
||||
modules: HashMap<&'static str, &'static str>,
|
||||
globals: RegistryKey,
|
||||
}
|
||||
|
||||
impl StaticSearcher {
|
||||
fn new(modules: HashMap<String, &'static str>, globals: RegistryKey) -> Self {
|
||||
fn new(modules: HashMap<&'static str, &'static str>, globals: RegistryKey) -> Self {
|
||||
Self { modules, globals }
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,7 @@ impl StaticSearcher {
|
||||
impl UserData for StaticSearcher {
|
||||
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||
methods.add_meta_method(MetaMethod::Call, |lua_ctx, this, name: String| {
|
||||
match this.modules.get(&name) {
|
||||
match this.modules.get(&name as &str) {
|
||||
Some(content) => Ok(Value::Function(
|
||||
lua_ctx
|
||||
.load(content)
|
||||
@ -79,7 +79,7 @@ pub trait AddSearcher {
|
||||
|
||||
/// Like `add_searcher`, but with Fennel source code encoded as
|
||||
/// `&'static str` to facilitate compile-time includes.
|
||||
fn add_static_searcher(&self, modules: HashMap<String, &'static str>) -> Result<()>;
|
||||
fn add_static_searcher(&self, modules: HashMap<&'static str, &'static str>) -> Result<()>;
|
||||
}
|
||||
|
||||
impl<'a> AddSearcher for Context<'a> {
|
||||
@ -93,7 +93,7 @@ impl<'a> AddSearcher for Context<'a> {
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn add_static_searcher(&self, modules: HashMap<String, &'static str>) -> Result<()> {
|
||||
fn add_static_searcher(&self, modules: HashMap<&'static str, &'static str>) -> Result<()> {
|
||||
let globals = self.globals();
|
||||
let searchers: Table = globals.get::<_, Table>("package")?.get("searchers")?;
|
||||
let registry_key = self.create_registry_value(globals)?;
|
||||
|
@ -24,7 +24,7 @@ fn add_searcher_works() {
|
||||
#[test]
|
||||
fn add_static_searcher_works() {
|
||||
let lume = read_lume_to_str();
|
||||
let name = "lume".to_string();
|
||||
let name = "lume";
|
||||
let mut map = HashMap::new();
|
||||
map.insert(name, lume);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user