-
Notifications
You must be signed in to change notification settings - Fork 248
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
Allow specifying the subxt
crate path for generated code
#664
Conversation
11c59c3
to
7e890a3
Compare
@@ -41,6 +42,7 @@ pub struct CompositeDef { | |||
|
|||
impl CompositeDef { | |||
/// Construct a definition which will generate code for a standalone `struct`. | |||
#[allow(clippy::too_many_arguments)] |
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.
Possibly create a follow-up ticket to refactor with a config struct instead of the params.
I haven't looked properly at the test you've added yet. One quicker thing you could do is to do all of the codegen with a custom path and check that the string "subxt" doesn't appear at all in it. Otherwise I wonder about tweaking the subxt crate import in the tests to be a custom path; at least if using acustom path is the default thing in the tests it'll get fairly well covered! |
codegen/src/types/derives.rs
Outdated
|
||
pub fn default_with_crate_path(crate_path: &CratePath) -> Self { | ||
Self { | ||
default_derives: Derives::default_with_crate_path(crate_path), |
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.
How about removing the Default
impls because we never want to be able to forget to provide a crate path?
This could then just be new
or new_with_crate_path
codegen/src/types/derives.rs
Outdated
impl Default for Derives { | ||
fn default() -> Self { | ||
Derives::default_with_crate_path(&CratePath::default()) | ||
} | ||
} |
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.
Should this exist? I think we should make sure crate path is always explicitly provided so we are forced to pass it through always (and thus can't accidentally forget).
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.
So to be on the same page: would this go through to the user-facing side? I.e. would each user always be required to specify ::subxt
as the crate path to use?
Looks great overall! I am happy with the tests (defaulting to checking that a custom path works everywhere I think is good enough for now and will almost certainly catch any issues there). Just a couple of wee comments; I think we should remove Default impls for things that rely on a crate path wherever possible just to make it hard for future us to miss threading the crate path through somewhere it's needed. |
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
Co-authored-by: Andrew Jones <ascjones@gmail.com>
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.
Looks great, thankyou @cmichi!
Closes #655.
We need this in ink! for use-ink/ink#1234.
I'm not particularly fond of the testing story for this feature, but I would also not duplicate all the existing tests. Hmm.