A Dynomite Realization
I recently ran into a feature of Dynomite
at work that was difficult to find initially, but incredibly useful to understand. For the uninitiated, Dynomite
gives you macros that make it really easy to serialize rust structs into DynamoDB objects. So for example you might do something like:
#[derive(Item)]
struct Order {
#[dynomite(partition_key)]
pk: String,
quantity: u16
}
Let’s say you now wanted to tag your orders with a generic set of tags:
Uh oh - this seems more annoying. Do we have to manually derive IntoAttribute
every time we use a HashMap
here? It turns out you can just derive the Attributes
(remember the s
) trait on your Tag to fix this!
While the Dynomite documentation does allude to using #derive[(Attributes)]
to do this, I never found an explicit example that showed how to resolve this error. And of course, all this works recursively, so you can keep deriving forever and ever and ever..