One struct, many tables... Reusable code? #2796
Unanswered
cryo-warden
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a struct that I want to split across different tables. The docs recommend reusing
spacetimedb::table
for this.So far so good!
However, I want some of my code to operate on every table for this struct.
Problem: The real code is much more complex than this, and I want to avoid repeating it if at all possible.
Is it really necessary that each table from the same struct be defined as a different type, even when they share all the same attributes? Is there any common type I could use to capture not only the
Table
trait, but also the indexes?In the meantime, I have simplified the code inside my loops as much as possible, making some logic reusable directly from my
Event
struct. The only parts I can't reuse are the iteration logic and anything which would go back to the corresponding event table, such as updating the record after processing.This is okay, but it feels like I'm failing to understand something that should be simple.
Update, 3 weeks later: After learning more about Rust macros, it looks like they're the ideal way to reduce boilerplate.
Beta Was this translation helpful? Give feedback.
All reactions