fix(progenitor-macro): if 'client.inner' is not set by user do not provide it to user-specified functions.#933
Conversation
…ovide it to user-specified functions.
|
Thanks for providing this, I came across this problem myself last week (and I 'fixed' it by providing documentation in this PR #934, which I'm happy to adapt once yours gets accepted). One thing to think about in future may be to move the inner type out of the scope of the code generator entirely, as well as the hook functions. So instead of generating a This way, you can generate to client in a separte crate, but provide inner type and hook functions in the crate where you use them. This would allow to ship crates with a generated client that can then be augmented with inner type and hook function wherever it is used, without the need for a generator. Also I find hook development easier this way, because all the macro magic no longer gets in the way. |
|
Thanks for this. Regarding the idea of a type parameter to Client. Another thing to throw into the mix is that I was thinking about making a Client trait so that consumers could use something of their own creation... or add some interposition/middleware-type stuff. |
…ovide it to user-specified functions. (oxidecomputer#933) Co-authored-by: Adam H. Leventhal <ahl@oxide.computer>
Description
When adding any hooks (
pre_async,post,pre) you were implicitly required to add an empty type just to fill inclient.innerproperty - even if you weren't actually using the client for anything. This mean that if you set an async hook without setting an inner client progenitor would create invalid code.We have changed that behaviour to only generate the
innerparameter if it's actually set by the end user.Previous Code
After Change
Future Work
Given we have a token stream of the hook body, we could try to identify the parameters required and be a little smarter... but this is already a big improvement.