feature request/concept: statically-typed+reexecutable alternative to trustfall_stubgen
#801
zombiepigdragon
started this conversation in
Ideas
Replies: 1 comment
-
I'm not sure I was able to fully understand the vision you have, but I'd be happy to see a prototype if you wanted to put one together!
|
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
First of all, I should preface this with the fact that I haven't had significant experience with trustfall, so I can't state with confidence that my conceptual usage pattern is correct or that it would work well. However, at my early point in the learning curve, I find myself wishing that the crate worked in the way I describe here.
My primary concern that leads to this feature request is that
trustfall_stubgen
generates some stringly-typed code, and is generally only run once to bootstrap the adapter. This works well if the schema is written prior to writing the adapter, but it is less well-suited to cases where the schema may change (the schema changes have to be manually transferred to the adapter without the tool's assistance, withcheck_adapter_invariants
detecting the changes when the test suite is run rather than on the next build). However, I believe a better solution would be to generate a "adapter" type (in a way similar totrustfall_stubgen
) which is generic over a "provider"/"implementation" type constrained to a generated trait. This trait would include all of the methods that currently contain atodo!
item, with the addition that some values, such as theproperty_name
, would be implemented as an enum for each function. The generated "adapter" generic type continues to be the type that implementsAdapter
as a trait, and it performs the current string-matching/unreachable!
to find the value of that enum.With this alternative model, each time the schema is changed, the generated module should be entirely regenerated, and the "provider"/"implementation" type would fail to compile due to differences in the trait or enums unless the new options are handled. With a concession to compile times (though possibly not a wise concession), this could even be implemented as a proc-macro so that the schema is updated every build.
I'm curious if this idea makes sense, or if it is fundamentally flawed in some way. I am very interested in hearing feedback from experienced users of this crate.
Beta Was this translation helpful? Give feedback.
All reactions