Only require str in new_with_name (#796)

* Only require `str` in `new_with_name`

It's a bit more idiomatic to have APIs require `&str` rather than
`String`, and the allocation doesn't matter much here since creating a
`Module` is pretty expensive anyway.

* Update a test
This commit is contained in:
Alex Crichton
2020-01-10 13:17:41 -06:00
committed by GitHub
parent 6571fb8f4f
commit 6b3ee47915
4 changed files with 14 additions and 20 deletions

View File

@@ -16,7 +16,7 @@ fn test_module_no_name() -> Result<(), String> {
let module = HostRef::new(
Module::new(&store, &binary).map_err(|e| format!("failed to compile module: {}", e))?,
);
assert_eq!(module.borrow().name().cloned(), None);
assert_eq!(module.borrow().name(), None);
Ok(())
}
@@ -36,19 +36,13 @@ fn test_module_name() -> Result<(), String> {
let module = HostRef::new(
Module::new(&store, &binary).map_err(|e| format!("failed to compile module: {}", e))?,
);
assert_eq!(
module.borrow().name().cloned(),
Some("from_name_section".to_string())
);
assert_eq!(module.borrow().name(), Some("from_name_section"));
let module = HostRef::new(
Module::new_with_name(&store, &binary, "override".to_string())
Module::new_with_name(&store, &binary, "override")
.map_err(|e| format!("failed to compile module: {}", e))?,
);
assert_eq!(
module.borrow().name().cloned(),
Some("override".to_string())
);
assert_eq!(module.borrow().name(), Some("override"));
Ok(())
}