-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Draft: RFC configuration in const context & HTTP-like protocol parsing support #129
Conversation
First commit makes the following usage possible: const CONFIG: super::ParserConfig = super::ParserConfig::const_default()
.allow_spaces_after_header_name_in_responses(true)
.allow_multiple_spaces_in_request_line_delimiters(true); which is otherwise rejected due to mutable references usage in const context. For my use case in particular, this is just ergonomics. I know quite specifically the configuration I need, and it won't be changed. Of course, there are workarounds, like using One thing though that I hoped to see is branch elimination. To be honest, I do not know enough about const propagation in Do you think something like this is worth a breaking change? |
Second commit is another stab at supporting HTTP-like protocols. The main idea is that The commit here is does not implement this idea fully. I used SIP as the example, the only difference there is in version parsing in the response, but I suppose there could be other protocols that could differ slightly more. Although as much as I would love to see this supported, this seems just a little bit out of project's scope. What do you think? Regarding performance, this is what I got before and after this commit:
Which is a weird result. I am benchmarking this on a laptop though, so there might actually be no meaningful difference and this is just a fluke. |
/// Sets first-line parsing to SIP | ||
pub const fn set_sip_protocol_parser(mut self) -> Self { | ||
self.version_parser = SIP_VERSION_PARSER; | ||
self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to see this as something like the following:
pub const fn set_protocol_parser(mut self, protocol: Protocol) -> Self {
self.version_parser = match protocol {
Protocol::Http => HTTP_VERSION_PARSER,
Protocol::Sip => SIP_VERSION_PARSER,
};
self
}
However, that gives the following compilation error:
error[E0658]: mutable references are not allowed in constant functions
--> src/lib.rs:287:31
|
287 | self.version_parser = match protocol {
| _______________________________^
288 | | Protocol::Http => HTTP_VERSION_PARSER,
289 | | Protocol::Sip => SIP_VERSION_PARSER,
290 | | };
| |_________^
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
which is weird :|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, is it only the attribute type, or the Protocol
enum too?
allow_multiple_spaces_in_request_line_delimiters: false, | ||
allow_multiple_spaces_in_response_status_delimiters: false, | ||
ignore_invalid_headers_in_responses: false, | ||
version_parser: HTTP_VERSION_PARSER, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the same reason, this also errors, but putting the function pointer in const
first makes it go away. Interesting.
I do not expect this PR to be merged as-is (or at all). The main purpose of this is to have a basis for discussion, hear different opinions and suggestions.
Some of the changes here are breaking, I'll leave additional information concerning each commit as a separate comment.