Add APIs to lookup values in Linker#1480
Add APIs to lookup values in Linker#1480alexcrichton merged 2 commits intobytecodealliance:masterfrom
Linker#1480Conversation
This commit adds three new methods to `Linker` in order to inspect it after values have been inserted: * `Linker::iter` - iterates over all defined values * `Linker::get` - lookup a value by its `ImportType` * `Linker::get_by_name` - lookup values based on their name Closes bytecodealliance#1454
Subscribe to Label ActionThis issue or pull request has been labeled: "wasmtime:api" Users Subscribed to "wasmtime:api"To subscribe or unsubscribe from this label, edit the |
| .collect::<Vec<_>>(); | ||
| for (name, item) in items { | ||
| self.linker.define(as_name, &name, item)?; | ||
| } |
There was a problem hiding this comment.
Could we factor out this logic too, with something like self.linker.alias(name, as_name) or so?
| if items.next().is_some() { | ||
| bail!("too many items named `{}` in `{}`", name, module); | ||
| } | ||
| return Ok(ret); |
There was a problem hiding this comment.
Could we factor this out into a method on Linker, something like self.linker.get_one_by_name(module, name) or so? I realize it'll require a special error type to be able to report both "no item named {}" and "too many items named {}", but this seems like it'll be a common use case -- I'm even picturing something like the wasmtime CLI but backed by a Linker so that you can provide multiple modules and then do --invoke.
|
All sounds reasonable to me, updated now! |
This commit adds three new methods to
Linkerin order to inspect itafter values have been inserted:
Linker::iter- iterates over all defined valuesLinker::get- lookup a value by itsImportTypeLinker::get_by_name- lookup values based on their nameCloses #1454