-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor wrap-rust bindings to use wrap::prelude::* #102
Conversation
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.
have you contemplated the case where two wraps has a type that has the exact same name? it happens here for example https://github.com/polywrap/wrap-test-harness/blob/master/cases/subinvoke/02-consumer/implementations/rs/lib.rs#L7
also i think that it would be super useful if, when updating wraps codegen; we can also update the wrap test harness just to check that it works; wdyt? |
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.
LGTM! This is a breaking change, so I think we should consider how to best handle that. Happy to chat on a call about this.
I think we will need to increase wrap-rust-abi-bindgen@1.0.0
to ...@2.0.0
. With the current polywrap
CLI we'll need to release a new breaking change there 0.12.0
.
A potentially better way to do this is to have the bindgen URI within the polywrap.yaml
manifest. Maybe something like:
source:
module: Cargo.toml
schema: ./polywrap.graphql
codegen:
abi_bindgen: wrapscan.io/polywrap/wrap-rust-abi-bindgen@2
This for sure! |
I think namespacing solves this already, right? |
Great idea |
All of that makes sense. I like the idea of adding a url to the manifest. I think this is a really small breaking change. I'm not sure a major version increase is necessary. I think this is more of a 1.0.0 -> 1.1.0 change. When someone updates their wrap, they just need to change this: pub mod wrap;
pub use wrap::*; to this: pub mod wrap;
pub use wrap::prelude::*; And possibly a few other imports. Everything else works the same. It is still possible to do something like What do you think? |
I am not sure (I think not if you ask me); that's why I think we should make sure of that in tests |
Okay. I am working on testing everything in the wrap test harness right now and will set up a PR that includes the changes necessary to prepare for the update. In the example you shared, one of the fn add_and_increment(args: ArgsAddAndIncrement) -> Result<i32, String> {
Ok(ImportedInvokeModule::add_and_increment( |
All sounds good @krisbitney, although I would say that if this change requires users to "fix" their wraps if they upgrade, then it is indeed a major version increase. But if |
Gotcha, okay. Using |
@krisbitney what I mean is that we have two |
Okay, I see. I want to emphasize the module structure has not changed. The types that were already being re-exported under When we import wraps, the bindings will still prepend their namespaces to their type names. For example, pub struct TestImportAnotherObject {
pub prop: String,
} When we look at types from imported wraps in pub use super::imported::test_import_object::TestImportObject;
pub use super::imported::test_import_another_object::TestImportAnotherObject;
pub use super::imported::test_import_enum::{
get_test_import_enum_key,
get_test_import_enum_value,
sanitize_test_import_enum_value,
TestImportEnum
};
pub use super::imported::test_import_enum_return::{
get_test_import_enum_return_key,
get_test_import_enum_return_value,
sanitize_test_import_enum_return_value,
TestImportEnumReturn
};
pub use super::imported::test_import_env::TestImportEnv;
pub use super::imported::test_import_module::TestImportModule;
pub use super::test_import::TestImport; In the example you shared, where the root wrap and its import had methods of the same name, there will be no issue because methods are not re-exported. Only the imported module is re-exported. |
Maybe I misunderstood what I was supposed to do and didn't re-export everything as I was supposed to? |
Here is how the wrap test harness will change: polywrap/wrap-test-harness#82 |
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.
All looks good to me! Also talked to @cbrzn yesterday and he agreed using prelude::*
is indeed best practice: https://github.com/search?q=prelude%3A%3A*&type=code
https://chat.openai.com/share/7152e9f6-c685-4c0b-b37b-e0dd8ac04f08
Closes polywrap/rust-wrap-client#237