Add partition/sort key getters to Item trait #146
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.
What did you implement:
The
Item
trait currently includes akey()
method that returns a map from attribute name to attribute value for either the partition key only or both the partition and sort keys. In the latter case, it's not possible to distinguish between the partition and sort key attributes without separate knowledge about which key is which.This PR adds
partition_key()
andsort_key()
methods to theItem
trait, which allow each key to be accessed separately. This makes it easier to write middleware and other generic code that works on multiple item types. Both methods are automatically implemented by thederive
proc macro.How did you verify your change:
Added some test cases, plus tested the code manually from my (separate) downstream crate.
What (if anything) would need to be called out in the CHANGELOG for the next release:
Since this PR adds new methods to the
Item
trait without providing a default implementation, it constitutes a breaking change for users that manually implement this trait rather than using thederive
proc macro.