Skip to content

Commit

Permalink
feat: add delete_by_name to imports/exports
Browse files Browse the repository at this point in the history
  • Loading branch information
vados-cosmonic committed Oct 17, 2023
1 parent 359fb1c commit b418dea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/module/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ impl ModuleExports {
_ => false,
})
}

/// Delete an exported function by name from this module.
pub fn delete_func_by_name(&mut self, name: impl AsRef<str>) -> Result<()> {
let fid = self
.get_func_by_name(name)
.context("failed to find exported func with name [{name}]")?;
self.delete(
self.get_exported_func(fid)
.context("failed to find exported func with ID [{fid:?}]")?
.id(),
);
Ok(())
}
}

impl Module {
Expand Down
17 changes: 17 additions & 0 deletions src/module/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ impl ModuleImports {
_ => None,
})
}

/// Delete an imported function by name from this module.
pub fn delete_func_by_name(
&mut self,
module: impl AsRef<str>,
name: impl AsRef<str>,
) -> Result<()> {
let fid = self
.get_func_by_name(module, name)
.context("failed to find imported func with name [{name}]")?;
self.delete(
self.get_imported_func(fid)
.context("failed to find imported func with ID [{fid:?}]")?
.id(),
);
Ok(())
}
}

impl Module {
Expand Down

0 comments on commit b418dea

Please sign in to comment.