-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat(stackable-versioned): Generate From implementations for automatic versions upgrades #790
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Techassi
force-pushed
the
feat/crd-versioning-from-impls
branch
from
May 23, 2024 14:58
044b659
to
7e16ec4
Compare
This commit separate the code into two crates: the core stackable-versioned crate, which provides a few utility traits and types and also re-exports the macros from the stackable-versioned-macros crate. This is because, crates (or libraries) marked as proc-macro libraries don't support export anything other than macro items. It also re-adds the basic From impl which was hard to keep across the previous merge conflict. This basic impl will currently panic, as the inner function is not yet implemented. This will follow. It additionally separates the generation code into multiple functions to more easily generate the different parts of code, like modules, struct fields and From impls.
There is at least one known rough edge: The #[allow(deprecated)] attribute is always included in the generated output, regardless if the individual From implementation actually needs it. The attribute is only required when the next version of the struct includes a field which is marked as deprecated.
Can be skipped both on the container level (no impls are generated) or at the version level (no impls are generated for that version).
NickLarsenNZ
reviewed
Jun 4, 2024
Techassi
changed the title
feat(stackable-versioned): Generate From implementations for automatic conversion between versions
feat(stackable-versioned): Generate From implementations for automatic versions upgrades
Jun 5, 2024
NickLarsenNZ
requested changes
Jun 5, 2024
NickLarsenNZ
approved these changes
Jun 5, 2024
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Tracked by stackabletech/issues#507, follow-up of #764,
blocked by #793This PR adds code generation for
From<OLD> for NEW
implementations to enable conversion between versions. The macro also allows to implement theFrom
trait by hand if customization is required.Additionally, it adds support to customize the default function (used in the automatically generated
From
impl) for added fields.Examples
Generated
From
implementationsSkip generating
From
implementationsThe generation can be skipped at the container level (no implementations are generated) or at the version level (only the generation from that to the next version is skipped).
Custom default function for added fields
Reviewer