Experiment: Allow Core to be wrapped in a middleware #317
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.
This is a bit work in progress, but it's a start of a potential approach to allowing "hybrid" shells - part written in Rust, part written in Kotlin/Swift/TypeScript...
The main change is an introduction of a
crux_core::Middleware
trait, which is implemented by theCore
and expected by theBridge
to be implemented by the provided core type. This allows middlewares to be inserted between the Bridge and the Core. Because the middleware may stack up, I've also switched the Core to return an iterator over effects, to avoid unnecessary allocations in case the middleware chain ends up long.As part of the experiment I've implemented a Key-Value capability using a HashMap for the storage, which catches the KV effects and resolves them against the store. It turns out it's pretty involved, because resolving he effects may produce follow up effects which need to also be potentially processed and so on, creating a mutually recursive loop.
Doing that with existing iterators turned out quite difficult, so I've resorted to an odd specialised queueing FlatMap sort of thing, which seems like it might be a beginning of some more helpful abstraction.
I'll keep this open for now so that folks can experiment and see how it works out for them and we can iterate on it before we land on something solid.
Note that this would be a breaking change, so I'd like us to get it right, rather than releasing five breaking iterations 😓