From 4aa2f52dd76300abdd001e13393b6431c06b626a Mon Sep 17 00:00:00 2001 From: Andy Weidenbaum Date: Mon, 15 Feb 2021 11:33:45 +1100 Subject: [PATCH] index StaticSearcher &'static str by &'static str credit - https://stackoverflow.com/questions/65549983/trait-borrowstring-is-not-implemented-for-str/65550108#65550108 --- src/searcher.rs | 10 +++++----- tests/tests.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/searcher.rs b/src/searcher.rs index 8281306..6e04ac1 100644 --- a/src/searcher.rs +++ b/src/searcher.rs @@ -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, + modules: HashMap<&'static str, &'static str>, globals: RegistryKey, } impl StaticSearcher { - fn new(modules: HashMap, 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) -> 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) -> 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)?; diff --git a/tests/tests.rs b/tests/tests.rs index 2e5586d..af2a9d2 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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);