Skip to content

Pass context and events as mutable references to postprocessors#68

Merged
zoni merged 1 commit intomainfrom
postprocessor-inputs-as-mutable-references
Jan 16, 2022
Merged

Pass context and events as mutable references to postprocessors#68
zoni merged 1 commit intomainfrom
postprocessor-inputs-as-mutable-references

Conversation

@zoni
Copy link
Owner

@zoni zoni commented Jan 9, 2022

Instead of passing clones of context and the markdown tree to postprocessors, pass them a mutable reference which may be modified in-place.

This is a breaking change to the postprocessor implementation, changing both the input arguments as well as the return value:

-    dyn Fn(Context, MarkdownEvents) -> (Context, MarkdownEvents, PostprocessorResult) + Send + Sync;
+    dyn Fn(&mut Context, &mut MarkdownEvents) -> PostprocessorResult + Send + Sync;

With this change the postprocessor API becomes a little more ergonomic to use however, especially making the intent around return statements more clear. It was inspired by/extracted from changes in #67.

Instead of passing clones of context and the markdown tree to
postprocessors, pass them a mutable reference which may be modified
in-place.

This is a breaking change to the postprocessor implementation, changing
both the input arguments as well as the return value:

```diff
-    dyn Fn(Context, MarkdownEvents) -> (Context, MarkdownEvents, PostprocessorResult) + Send + Sync;
+    dyn Fn(&mut Context, &mut MarkdownEvents) -> PostprocessorResult + Send + Sync;
```

With this change the postprocessor API becomes a little more ergonomic
to use however, especially making the intent around return statements more clear.
@zoni zoni mentioned this pull request Jan 9, 2022
@zoni zoni merged commit d25c6d8 into main Jan 16, 2022
@zoni zoni deleted the postprocessor-inputs-as-mutable-references branch January 16, 2022 10:53
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.

1 participant