-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add APIs to lookup values in Linker
#1480
Conversation
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 |
crates/wast/src/wast.rs
Outdated
.collect::<Vec<_>>(); | ||
for (name, item) in items { | ||
self.linker.define(as_name, &name, item)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we factor out this logic too, with something like self.linker.alias(name, as_name)
or so?
crates/wast/src/wast.rs
Outdated
if items.next().is_some() { | ||
bail!("too many items named `{}` in `{}`", name, module); | ||
} | ||
return Ok(ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
This commit adds three new methods to
Linker
in order to inspect itafter values have been inserted:
Linker::iter
- iterates over all defined valuesLinker::get
- lookup a value by itsImportType
Linker::get_by_name
- lookup values based on their nameCloses #1454