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.
Motivation
I want to return http bodies of different types, for example from multiple match branches. The easiest way to do this is to box the body like:
But in the case of the body type from the
ServeFile
/ServeDir
service, I have to box what is already boxed. This requires double allocation and, more critically, double indirection. I would like to avoid these overhead costs.Solution
My proposal to add a conversion impl into the
UnsyncBoxBody
type. This eliminates the need for additional boxing:Alternatives
Either
type, but it's not convenient with more than two different types. I could do infinite levels of nesting, but I want a more straightforward solution.fallback
method, but I want to resolve routes at a higher level, e.g. preferring a route even if a file with same name exists.Pin<Box<dyn Body<Data = D, Error = E> + Send>>
type.