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

[Suggestion] Type state pattern for transactions #36

Open
acul009 opened this issue Jan 28, 2024 · 0 comments
Open

[Suggestion] Type state pattern for transactions #36

acul009 opened this issue Jan 28, 2024 · 0 comments

Comments

@acul009
Copy link

acul009 commented Jan 28, 2024

Hi,

I'm coming from go and was looking for something similar to boltdb.
After finding your project and starting to learn rust, I wanted to ask if it would be feasible to implement the typestate pattern for transactions.

Instead of just allowing to call tx() with a bool you could also call ro() or rw() which would give a transaction without any of the write functions even available. That way you could catch these errors at compiler time.

If you think this is a good idea, I'd be happy to do a bit of gruntwork for adding the state to each neccesary type.
I don't think I can handle all problems however, so I'd be grateful for some help later on.

I would suggest these 3 TypeStates:

  • Legacy (would be used when tx is called)
  • ReadOnly
  • WriteOnly

This way other projects will still function, while enabling compiler type checking the transaction type.

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

No branches or pull requests

1 participant