rewrite config & context, support tokio::main & tokio::test #2937
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 bigger refactor and I have to apologize in advance for the size of it. I have ~8 WIP branches where I tried to do only parts of the rewrite, but all failed and now I ended up doing many things at once.
The initial motivation of this is coming from wanting to make progress on the sync/async migration in our codebase. Plenty of things were and still are not in the state I want them to be.
For some parts I took inspiration from the crates.io codebase and how they do it, which I like.
To wrap it up, this PR:
Configstruct to include a builder.Contexttrait to astructthat just includes everything. This made much of the migration much easier, less lifetime errors.tokio::runtime::Runtimedirectly, now work with atokio::runtime::Handle. This enables us to usetokio::testand also later migrate ourmainfunction totokio::main.TestEnvironmentin your test, and the cleanup happens in theDropimpl.some detail notes about the implementation:
bonbecause I like its design more, and crates.io uses it too, but since I wanted to "stack" the builder calls it was too annoying to work with.wrapperusage with the "new way".override_configfor now, some some selected ones. The rest follows later.known limitations for now:
tokio::testdoesn't work, it only works withflavor = multi_thread. This is because I want to useblock_in_placeto be able to teardown the test env inDrop. I took this from crates.io.after this PR I imagine:
async_wrapper