-
Notifications
You must be signed in to change notification settings - Fork 825
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
Added function to merge ImportObjects #190
Conversation
Don't be too hard on yourself. Many of us are still learning rust 😄. This code looks great! Would you be willing to write some unit tests? |
lib/runtime-core/src/import.rs
Outdated
@@ -79,6 +80,46 @@ impl ImportObject { | |||
pub fn get_namespace(&self, namespace: &str) -> Option<&(dyn LikeNamespace + 'static)> { | |||
self.map.get(namespace).map(|namespace| &**namespace) | |||
} | |||
|
|||
pub fn merged(mut imports_a: ImportObject, mut imports_b: ImportObject) -> Self { |
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.
I think merge
may be a better name.
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.
Sounds good to me.
Yeah, I can write some tests, I just haven't done that before in Rust. Are the tests in |
@tprk77 We do not have any conventions for this kind of testing. You can't do anything wrong by making tests. If we feel like reorganizing, we will, but the win with tests outweighs any refactoring costs in the future. For now, putting the tests in the same file is fine. Cargo will find the tests no matter what when we run #[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_merge imports() {
// assert!(truthy_thing, "message if fails")
}
} |
lib/runtime-core/src/import.rs
Outdated
@@ -79,6 +80,46 @@ impl ImportObject { | |||
pub fn get_namespace(&self, namespace: &str) -> Option<&(dyn LikeNamespace + 'static)> { | |||
self.map.get(namespace).map(|namespace| &**namespace) | |||
} | |||
|
|||
pub fn merged(mut imports_a: ImportObject, mut imports_b: ImportObject) -> Self { |
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.
Can you also add some documentation here about the behavior of this method during edge cases (e.g. Two items with the same name)?
ce13820
to
9d81261
Compare
Ok, I think I've got everything in order. Let me know if I need to add or change anything else. |
9d81261
to
9065fe4
Compare
@tprk77 we are thinking on adding an |
@syrusakbary Sounds like a good idea. I wouldn't mind working on it. I have a question about the details. I have mostly been thinking of If it's analogous to a set, it should just add a namespace to the set. I think using |
811fcc5
to
eaa1a4f
Compare
I implemented iterators for import objects and like-namespaces. I wrote tests for both. Implementing the iterator for I got rid of the I kept the merge function mostly the same for now, since I'm not sure what you want to do with that. Please send your comments my way, I'm still happy to work on this. |
eaa1a4f
to
89445a5
Compare
89445a5
to
39a1658
Compare
This PR doesn't work anymore. |
I thought I would try implementing the
ImportObject
merging I needed. The main use case is merging the Emscripten imports fromgenerate_emscripten_env
with the usual ones, i.e.,print_str
from thewasmer-rust-example
.Here's where I'm using it, in my attempt to update the
wasmer-rust-example
to run Emscripten stuff:https://github.com/tprk77/wasmer-rust-example/blob/emscripten-wip/src/main.rs
Apologies in advance if my code is wacky, I'm still kind of learning Rust. I'd appreciate any feedback you might have.