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

fix derived ItemKey field rename and impl derive(Attributes) #115

Merged
merged 10 commits into from
Jul 14, 2020

Conversation

softprops
Copy link
Owner

@softprops softprops commented Jul 14, 2020

What did you implement:

addresses issue with renaming partition key fields which has an affect on derived ItemKey struct when it breaks with rust's conventions.

Closes: #108, #107, #79

How did you verify your change:

unit test and compiler warning checks

What (if anything) would need to be called out in the CHANGELOG for the next release:

a number of related things that are open issues were at play. ItemKey's derive impls clone partition and sort keys from Item structs and rewrote them to their deserialized names but in struct field form yielding less than ideal results when renamed to using non-rust naming conventions.

The impl of this derived(Item) who's impl for deriving Item keys will silently omit generating another ItemKey struct if a partition_key is absent. This was to work around an infinite compilation phase loop. An artifact of this is that there's no check in derive Item to ensure Items actually have partition key defined.

The following things where resolved in this change

  • ItemKey structs derivation now simply clone fields but retain attributes to keep rename/default attrs ect
  • Item derivation now guarantees at compile time that an Item declares a partition key
  • ItemKey struct derivation can no longer derive Item because of the above, instead it derives Attributes
  • Attributes as mentioned above was a missing component for cases were you want to deserialize a projected set of item fields not including the partition key itself

whew.

@@ -115,6 +115,7 @@ fn parse_attrs(all_attrs: &[Attribute]) -> Vec<Attr> {
/// # Panics
///
/// This proc macro will panic when applied to other types
//#[proc_macro_error::proc_macro_error]
Copy link
Owner Author

Choose a reason for hiding this comment

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

note to self: revisit this before merging. it seems the proc_macro_error crate requires this and I didn't catch that last time.

@softprops softprops changed the title add a test to demostrate current key derivation behavior fix derived ItemKey field rename and impl derive(Attributes) Jul 14, 2020
// impl Attribute for Name (these are essentially just a map)
let attribute = quote!(::dynomite::Attribute);
let impl_attribute = quote! {
impl #attribute for #name {
Copy link
Owner Author

Choose a reason for hiding this comment

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

we need to derive Attribute since embedded structs within Items need to be viewed as an Attribute. It turns out that makes this impl quite simple since its basically just a map of attributes anyway!

@softprops softprops marked this pull request as ready for review July 14, 2020 06:05
@softprops softprops force-pushed the item-key-struct-field-renames branch from 958e2b2 to cc49dd5 Compare July 14, 2020 09:12
@softprops
Copy link
Owner Author

generating some compile tests. noting for future reference. TRYBUILD=overwrite cargo t -- --nocapture try_build_tests is super dope

@softprops softprops merged commit 49d6b77 into master Jul 14, 2020
@softprops softprops deleted the item-key-struct-field-renames branch July 14, 2020 15:30
@Veetaha
Copy link
Contributor

Veetaha commented Jul 14, 2020

Wow, this is awesome, looking forward for 0.9 release!

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.

Compiler warnings about member name casing when deriving Item and renaming partition/sort key
2 participants