Skip to content

ConnectInfo extractor no longer accepted in middleware::from_fn_with_state #2369

Answered by davidpdrsn
leonardoarcari asked this question in Q&A
Discussion options

You must be logged in to vote

Ah yes that makes sense. Request<Body> is not !Sync (because as you say Body is !Sync). That means &Request<Body> is !Send meaning the future returned by record_visitors_stats is also !Send and that makes it not compile. So you'll have to pass the headers directly.

The reason Body is !Sync is that you can't really do anything with &Body from multiple threads since streaming it requires a &mut Body (or rather a Pin<&mut Body>). So therefore streams are normally not !Sync. Another example of this is BoxStream from futures.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@leonardoarcari
Comment options

@davidpdrsn
Comment options

Answer selected by leonardoarcari
@leonardoarcari
Comment options

@an1217
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2368 on November 28, 2023 17:26.