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:
@@ -27,7 +27,7 @@ impl Resolver for SimpleResolver<'_> {
|
||||
pub fn instantiate_in_context(
|
||||
data: &[u8],
|
||||
imports: &[Extern],
|
||||
module_name: Option<String>,
|
||||
module_name: Option<&str>,
|
||||
context: Context,
|
||||
exports: Rc<RefCell<HashMap<String, Option<wasmtime_runtime::Export>>>>,
|
||||
) -> Result<(InstanceHandle, HashSet<Context>), Error> {
|
||||
@@ -74,7 +74,7 @@ impl Instance {
|
||||
let (mut instance_handle, contexts) = instantiate_in_context(
|
||||
module.binary().expect("binary"),
|
||||
externs,
|
||||
module.name().cloned(),
|
||||
module.name(),
|
||||
context,
|
||||
exports,
|
||||
)?;
|
||||
|
||||
@@ -270,9 +270,9 @@ impl Module {
|
||||
/// data. The provided `name` will be used in traps/backtrace details.
|
||||
///
|
||||
/// See [`Module::new`] for other details.
|
||||
pub fn new_with_name(store: &Store, binary: &[u8], name: String) -> Result<Module> {
|
||||
pub fn new_with_name(store: &Store, binary: &[u8], name: &str) -> Result<Module> {
|
||||
Self::validate(store, binary)?;
|
||||
unsafe { Self::create(store, binary, Some(name)) }
|
||||
unsafe { Self::create(store, binary, Some(name.to_string())) }
|
||||
}
|
||||
|
||||
/// Creates a new WebAssembly `Module` from the given in-memory `binary`
|
||||
@@ -376,8 +376,8 @@ impl Module {
|
||||
|
||||
/// Returns identifier/name that this [`Module`] has. This name
|
||||
/// is used in traps/backtrace details.
|
||||
pub fn name(&self) -> Option<&String> {
|
||||
self.inner.name.as_ref()
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.inner.name.as_deref()
|
||||
}
|
||||
|
||||
/// Returns the list of imports that this [`Module`] has and must be
|
||||
|
||||
Reference in New Issue
Block a user