Idea: Box services internally _and_ store the complete type #393
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.
Note this branch currently includes #385. That makes the diff larger than it actually is.
All compile issues we've had comes from building very large types and rust not being very good at evaluating trait bounds on them. A common workaround is to use boxing to erase the types. People have suggested that axum internally box all routes. I've been reluctant to do that because I wanted to keep as much type information as possible so we could use it to do cool stuff, like generating OpenAPI specs purely based on the types.
Today I had an idea though, what if we both boxed all services and kept the type information? For example
Route
could be defined as:Service
can then be implemented from these trait bounds:Notice here that there is no bounds on
S
. Thats becauseRoute.svc
is already aService
. No new bounds necessary.Router::boxed
can be defined like it used to be:With these changes code like this:
compiles quickly. Previously it would take ages.
I think this approach is quite interesting and definitely something I'll look more into. Some todos
Router::boxed
#385 fixes issues withRouter::boxed
. Does this solve other problems that Fix compile time issues withRouter::boxed
#385 doesn't solve?