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

spike: Improve the quality/ readability of generated validation rust code #390

Open
c12i opened this issue Sep 16, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@c12i
Copy link
Collaborator

c12i commented Sep 16, 2024

Goals

  • Explore the possibility of using declarative macros to reuse a lot of repeated code

  • Firstly, identify instances of repeated code in the validation logic and identify code
    that can be grouped into a single macro

@c12i c12i self-assigned this Sep 16, 2024
@c12i c12i transferred this issue from holochain/Components Oct 15, 2024
@c12i c12i added the enhancement New feature or request label Oct 15, 2024
@mattyg
Copy link
Member

mattyg commented Oct 25, 2024

My vague idea is that we could have a ValidateEntry trait that you implement for each entry type. The ValidateEntry trait has a few functions validate_create, validate_update, validate_delete which by default return ValidateCallbackResult::Valid (or don't have a default implementation if we want to force app devs to be explicit).

Then we do some refactoring of the Op transformation such that we can just run the validate function for that entry type with the provided data.

For LinkTypes, rust doesn't allow enum variants to impl traits so we might have to come up with some workaround - either a change to the hdk for how you define a LinkType, or something at the app level to associate a linktype variant to a trait implementation.

I know this is vague and definitely would need an exploratory spike to feel it out. But I think this could be ideal -- if it worked then scaffolding and app devs may never have to touch the validate callback, and can just implement this trait for their entry & link types.

I started playing with such a spike a while back and didn't get very far (it is half-baked and does not compile), but maybe the source code can give you some idea of what I'm hoping for: mattyg/forum-example-android-build-ci@df51808#diff-c97ee58a611be9db354b14901907057f063e14c498e3c1748185367ba231095b

@c12i c12i removed their assignment Nov 5, 2024
@c12i c12i changed the title refactor: Improve the quality/ readability of generated validation rust code spike: Improve the quality/ readability of generated validation rust code Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Ready for refinement
Development

No branches or pull requests

2 participants