-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement common trait(s) to expose common traits of HTTP message (header) types #592
Comments
If we opt to implement |
It'd probably be helpful to know if there's much other prior art of I think a larger trait gets complicated quickly, and people could rightly ask why they return concrete types instead of associated types, which doing it with associated types gets gnarly in its own way. |
What kind of prior art are you looking for? For one thing, the http-types crate (which the async-std community started at some point, I think?) has I can't think of many downsides. I guess it forces all implementers to share the same types internally, which they do already and this seems pretty fundamental to their operation.
I don't follow how associated types would be useful here -- also don't see much complexity in the larger trait in general, the definition I presented above seems pretty minimal and robust to changes. But I'd be happy with the most minimal take that only implements |
All HTTP messages in the http crate contain a bunch of shared data: the
version
, theheaders
and theextensions
. Both theRequest
and theResponse
also allow callers to separate the headers part of a message from the body, resulting in twoParts
types that both carry all three of these fields, so there are 4 types in total that share the same underlying data. It would be nice if there was a way to abstract over this data.For my purposes, I mostly care about the
HeaderMap<HeaderValue>
-- my direct use case is that I have a function that makes it easier to extract the header's value as a&str
and would like to apply this easily to both arequest::Parts
(which our framework uses internally to carry around request state) and aResponse
-- but it might make sense to take care of all three in one interface.We could just have four
impl AsRef<HeaderMap<HeaderValue>>
for all four of these types as a minimal solution, or we could implement a custom trait, maybe like this:The text was updated successfully, but these errors were encountered: