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:
Andy Weidenbaum 2021-02-15 11:33:45 +11:00
parent f159a7cc27
commit 4aa2f52dd7
2 changed files with 6 additions and 6 deletions

View File

@ -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)?;

View File

@ -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);