-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat(stackable-versioned): Add support for versioned enums #813
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cb8fbc9
Update changelog
Techassi d2641d4
Update PR link in the changelog
Techassi 52b4536
Merge branch 'main' into feat/crd-versioning-enum-support
Techassi 6721b0c
Start to move code, add enum impls
Techassi f98598a
Introduce generalized structs for containers and items
Techassi 124811f
Finish traits and generic types
Techassi 28048a1
Use From<&ContainerAttributes> for Vec<ContainerVersion> implementation
Techassi f524d32
Merge branch 'main' into feat/crd-versioning-enum-support
Techassi b315baf
Finish basic enum code generation
Techassi 18e54c1
Use darling(flatten) for field attrs
Techassi e173aba
Replace unwraps with expects
Techassi 96381d7
Generate code for all item states
Techassi c125b98
Start adding From ipls for enum conversion
Techassi 161380c
Merge branch 'main' into feat/crd-versioning-enum-support
Techassi 169d716
Finish basic From impls for enums
Techassi 0fed8bc
Merge branch 'main' into feat/crd-versioning-enum-support
Techassi 69e4977
Apply suggestions
Techassi 68b28ec
Apply more suggestions
Techassi 758e885
Rename starts_with variable to starts_with_deprecated
Techassi 028fc3c
Remove old todo comment
Techassi 7cf7396
Add auto-generated notes for deprecated versions
Techassi de1cde3
Move attribute parsing into new() functions
Techassi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
84 changes: 84 additions & 0 deletions
84
crates/stackable-versioned-macros/src/attrs/common/item.rs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use darling::{util::SpannedValue, Error, FromMeta}; | ||
use k8s_version::Version; | ||
use proc_macro2::Span; | ||
use syn::Path; | ||
|
||
/// These attributes are meant to be used in super structs, which add | ||
/// [`Field`](syn::Field) or [`Variant`](syn::Variant) specific attributes via | ||
/// darling's flatten feature. This struct only provides shared attributes. | ||
#[derive(Debug, FromMeta)] | ||
#[darling(and_then = ItemAttributes::validate)] | ||
pub(crate) struct ItemAttributes { | ||
/// This parses the `added` attribute on items (fields or variants). It can | ||
/// only be present at most once. | ||
pub(crate) added: Option<AddedAttributes>, | ||
|
||
/// This parses the `renamed` attribute on items (fields or variants). It | ||
/// can be present 0..n times. | ||
#[darling(multiple, rename = "renamed")] | ||
pub(crate) renames: Vec<RenamedAttributes>, | ||
|
||
/// This parses the `deprecated` attribute on items (fields or variants). It | ||
/// can only be present at most once. | ||
pub(crate) deprecated: Option<DeprecatedAttributes>, | ||
} | ||
|
||
impl ItemAttributes { | ||
fn validate(self) -> Result<Self, Error> { | ||
// Validate deprecated options | ||
|
||
// TODO (@Techassi): Make the field 'note' optional, because in the | ||
// future, the macro will generate parts of the deprecation note | ||
// automatically. The user-provided note will then be appended to the | ||
// auto-generated one. | ||
|
||
if let Some(deprecated) = &self.deprecated { | ||
if deprecated.note.is_empty() { | ||
return Err(Error::custom("deprecation note must not be empty") | ||
.with_span(&deprecated.note.span())); | ||
} | ||
} | ||
|
||
Ok(self) | ||
} | ||
} | ||
|
||
/// For the added() action | ||
/// | ||
/// Example usage: | ||
/// - `added(since = "...")` | ||
/// - `added(since = "...", default_fn = "custom_fn")` | ||
#[derive(Clone, Debug, FromMeta)] | ||
pub(crate) struct AddedAttributes { | ||
pub(crate) since: SpannedValue<Version>, | ||
|
||
#[darling(rename = "default", default = "default_default_fn")] | ||
pub(crate) default_fn: SpannedValue<Path>, | ||
} | ||
|
||
fn default_default_fn() -> SpannedValue<Path> { | ||
SpannedValue::new( | ||
syn::parse_str("std::default::Default::default").expect("internal error: path must parse"), | ||
Span::call_site(), | ||
) | ||
} | ||
|
||
/// For the renamed() action | ||
/// | ||
/// Example usage: | ||
/// - `renamed(since = "...", from = "...")` | ||
#[derive(Clone, Debug, FromMeta)] | ||
pub(crate) struct RenamedAttributes { | ||
Techassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub(crate) since: SpannedValue<Version>, | ||
pub(crate) from: SpannedValue<String>, | ||
} | ||
|
||
/// For the deprecated() action | ||
/// | ||
/// Example usage: | ||
/// - `deprecated(since = "...", note = "...")` | ||
#[derive(Clone, Debug, FromMeta)] | ||
pub(crate) struct DeprecatedAttributes { | ||
Techassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub(crate) since: SpannedValue<Version>, | ||
pub(crate) note: SpannedValue<String>, | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod container; | ||
mod item; | ||
|
||
pub(crate) use container::*; | ||
pub(crate) use item::*; |
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub(crate) mod container; | ||
pub(crate) mod common; | ||
pub(crate) mod field; | ||
pub(crate) mod variant; |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.