Why does trait FromRequestParts
require &mut Parts
and not just &Parts
?
#2190
Replies: 2 comments
-
For implementers of the trait, this is not a restriction, it increases the set of things you can do in the extractor. Yes, it's not common to mutate the request parts when extracting, but I find it nice that users are given the option to do so if they want. Is this somehow problematic for a use case you have? |
Beta Was this translation helpful? Give feedback.
-
axum has always given a mutable reference. In 0.5 and earlier extractors were given a &mut RequestParts which also allow mutation. There are some legitimate use cases for that such as WebSocketUpgrade removing the OnUpgrade. Owned of that is required to upgrade the connection. |
Beta Was this translation helpful? Give feedback.
-
Hello. Are there any reasons, apart from historical ones, why does it require a mutable reference? Because it seems semantically wrong to me. And standard extractors don't mutate
Parts
, as far as I know. Yes, in the pastHeaderMap
extractor did mutate in order to take out the headers instead of cloning them. But some time agoaxum
devs changed this because users weren't satisfied with the errors they were getting in some use cases. And cloning headers isn't really as expensive, compared to cloning the body. So in e. g. axum 0.7 maybe it makes sense to replace&mut
with&
? For example, bothactix-web
androcket
ask for just immutable references: https://docs.rs/actix-web/latest/actix_web/trait.FromRequest.html https://api.rocket.rs/v0.4/rocket/request/trait.FromRequest.htmlBeta Was this translation helpful? Give feedback.
All reactions