Improve imports ergonomics

This commit is contained in:
Lachlan Sneff 2019-01-08 22:23:07 -05:00
parent 82771673b5
commit cfaa9ff494
2 changed files with 6 additions and 6 deletions

View File

@ -12,8 +12,8 @@ fn main() -> Result<(), String> {
let mut imports = Imports::new();
imports.add(
"env".to_string(),
"print_num".to_string(),
"env",
"print_num",
Import::Func(
unsafe { FuncRef::new(print_num as _) },
FuncSig {

View File

@ -169,11 +169,11 @@ impl Imports {
}
}
pub fn add(&mut self, module: String, name: String, import: Import) {
pub fn add(&mut self, module: impl Into<String>, name: impl Into<String>, import: Import) {
self.map
.entry(module)
.or_insert(HashMap::new())
.insert(name, import);
.entry(module.into())
.or_insert_with(|| HashMap::new())
.insert(name.into(), import);
}
pub fn get(&self, module: &str, name: &str) -> Option<&Import> {