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

Implement postprocessors using traits #184

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rsesek
Copy link
Contributor

@rsesek rsesek commented Oct 8, 2023

These are like the Postprocessor callback function type, but they can be implemented on types for more ergonomic stateful postprocessing.

Fixes #175


I've structured this as two commits:

  1. Adds the trait definitions and uses an enum to store the postprocessors
  2. Change the pub definition of Postprocessor from the type to a trait

It is possible to avoid introducing a second set of methods on Exporter, and the code could be changed so that add_postprocessor just takes a &'a dyn Postprocessor and the add_*_impl methods wouldn’t need to be added. However, that breaks some existing callers that use closures without typed arguments. It seems the compiler cannot infer the closure argument types when implicitly converting between the closure and the Fn pointer.

I tried to make it so that the existing add_postprocesor method could take an impl as well as continuing to take the callback type. But I couldn’t get that to work while also still allowing concise closure syntax with omitting the parameter types (it seems that for the closure type inference to work, every closure would need to fully specify the callback type signature).

Opening this PR more as a discussion point, and I understand if this isn’t something you want to add. With the other commit for #175, this is more just an API ergonomics enhancement.

rsesek added 2 commits October 8, 2023 14:01
These are like the Postprocessor callback function type, but they can
be implemented on types for more ergonomic stateful postprocessing.

Fixes zoni#175
This creates a parallel EmbedPostprocessor trait, and it adds new
methods for registering trait objects into the postprocessor chains. The
trait is implemented for the callback Fn type that was previously
declared as the Postprocessor type.
@rsesek rsesek force-pushed the postprocessor-improvements branch from 338867c to 1fcdd9d Compare October 8, 2023 19:14
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

Successfully merging this pull request may close these issues.

Postprocessor type does not enable storing state in the postprocessor
1 participant