Implement hooks via a trait and autoref specialization #1121
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So far we've allowed progenitor consumers to customize the generated code to calls to custom code before (pre-) and after (post-) the execution of all HTTP requests. This has been fine, but we've introduced now 4 variants with both overlap and significant limitation. In particular, when we wanted to include additional debugging output to our generated CLI, it turned out to be quite awkward and it wasn't clear how we could achieve our goals without also screwing up the SDK's interface.
This PR proposes a new trait that looks like this:
Generated code will implement this by default for
&Client
. Consumers who wish to customize things get to do so by simplyimpl ClientHooks for Client { .. }
adjacent to the generated code. Today, hooks are specified in hard-to-debugquote! { }
generatedTokenStream
s; with this change, we can effectively do the same thing--and more--in normal Rust code.I'm not wed to aspects of the interface. For example, I thought that
wrap
would be useful, but now I'm not sure it is, so perhaps we remove it. I'm not sure of the appropriate return type for all of these methods--we may want to further modify theprogenitor_client::Error
type to adapt it to this new modality.If this works out, I would definitely like to deprecate and/or remove the existing hooks as they're finicky, weird, poorly document, and hard to document.
You can see an example if this in action here: oxidecomputer/oxide.rs#1081. It does seem a bit more reasonable than the current mechanism.