Skip to content
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

Extract macro to new crate #93

Merged
merged 4 commits into from Jun 12, 2023

Conversation

mo8it
Copy link
Contributor

@mo8it mo8it commented Jun 11, 2023

Closes #31 (comment)

Updated the edition to 2021 and removed extern crate proc_macro; because it did not help at the end: #57 (comment)

@mo8it
Copy link
Contributor Author

mo8it commented Jun 12, 2023

@idanarye I am not sure about what to do with the bottom types for repeated and required fields: #31 (comment)

You said that you would like to remove the one for required fields and keep the one for repeated fields, but on the other hand, the error for repeated fields points to the method with the name of the field. Therefore, we could just replace both bottom types with Missing_Required_Fields and Repeated_Field_Assignment.

}
pub use typed_builder_macro::TypedBuilder;

#[doc(hidden)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it's an official trait in its own crate, I think it should be exposed and documented. I can add the documentation myself later though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't see a value in exposing the trait. Adding it to the documentation whould be a distraction since it is only used internally in the code generated by the macro.

But adding a normal comment would be nice.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly a direct copy-paste, right? (github won't show a proper diff because of the new src/lib.rs...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would mention changes that are not obvious from the commit messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did replace make_punctuated_single with the implementation of FromIterator. That is not obvious.

@idanarye
Copy link
Owner

This is weird, but now that I check again the repeated value error does not show the type in the rust-analyzer virtual text diagnostics and missing value does:

image

This is the opposite of what I've observed in #31. But it's actually better, because repeated value is easy to figure out even without the type name as the hint.

This means that I no longer mind having a Repeated_Field_Assignment, but I still want to generate Missing_Required_Field_*. Maybe when we get a const generic string we can use that instead.

@mo8it
Copy link
Contributor Author

mo8it commented Jun 12, 2023

Because of this change which might be dependent on the editor, I personally would prefer leaving things as are and migrating to a better, less hacky option as you mentioned later.

Therefore, I mark this PR as ready to merge, but if you want to remove the repeated field enums, I can still do it.

@mo8it mo8it marked this pull request as ready for review June 12, 2023 15:51
@idanarye idanarye merged commit d62509f into idanarye:master Jun 12, 2023
8 checks passed
@mo8it mo8it deleted the extract_macro_to_new_crate branch June 12, 2023 16:28
@mo8it
Copy link
Contributor Author

mo8it commented Jun 12, 2023

@idanarye Thanks for merging!

We might need to adjust the CI if we add tests to the macro crate. I think we should use a workspace and add --workspace to the cargo test command. Should I submit a PR?

@idanarye
Copy link
Owner

Why? All the tests are still main crate, not the proc-macro crate. They still run with a regular cargo test.

@mo8it
Copy link
Contributor Author

mo8it commented Jun 12, 2023

I just thought about the scenario of adding a test to subcrates that would not be run in the CI.

Aslong as we keep all tests there, there is no problem.

@idanarye
Copy link
Owner

All the tests go in the tests directory at the project's root. I don't see why there should ever be a need to add some to the macro subcrate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split the proc macro to dependency crate
2 participants