-
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
Add Method::from_static #595
base: master
Are you sure you want to change the base?
Conversation
5dc2a6b
to
d9a6f0b
Compare
b2fa38f
to
7107737
Compare
Oh, I just realised that CI failed due to |
We could probably update the MSRV, depending on what the version required is and how old it is. |
Rust 1.57.0, from 2021-12-02 |
For tokio, the current MSRV is 1.56.0. |
7107737
to
7232c97
Compare
I've updated the PR to panic without We can remove this hack (both this new instance and existing ones) once the MSRV is bumped to 1.57.0 or greater. |
7232c97
to
755c3b4
Compare
I was wondering if we could add a variant |
I don't know of any methods that are longer than 15 bytes, so I'm not sure that it's worth the effort. |
What's this stuck on? |
755c3b4
to
b275280
Compare
I would also like to see this being merged as it helps with implementing a webdav server base on hyper
recently I stubbled over the
figured out that this wouldn't work with the current implementation since the equality also checks the enum variant wich is required that |
@seanmonstar Anything that needs to be done to land this? Happy to help if there's anything to do. |
Allows creating constant `Method` instances, e.g.: const PROPFIND: Method = Method::from_static(b"PROPFIND"); Fixes: hyperium#587
I explored this a bit further. Adding a new enum variant won't increase the total size of I've implemented your suggestions. This remove the conditional (compile-time) panic if len > 15. |
b275280
to
c0261d6
Compare
At this point, waiting for feedback from the core devs. |
b"PATCH" => Method::PATCH, | ||
src => { | ||
if src.len() <= 15 { | ||
let inline = InlineExtension::from_static(src); |
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.
With an ExtensionStatic
available, is there a benefit to keeping this one?
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.
InlineExtension
has no heap allocation and has the data available in the same allocation. Most HTTP methods fit in this case, and it has no overhead.
ExtensionStatic
is a niche for unusually long methods, but has a heap allocation and an extra indirection.
We have three options here:
- Keep both. No real downsides aside from another internal type, and does not increase the size of the
Method
type. - Keep only
InlineExtension
, restrictingfrom_static
to only methods oflen <= 15
. - Keep only
ExtensionStatic
, forcing anyfrom_static
method to use a heap allocation and an extra indirection.
Personally, I prefer the first choice the most, and the third one the least (since it introduces pointless overhead for most WebDAV methods, albeit minor).
I found the Problem with const BASELINE_CONTROL: Method = Method::from_static(„BASELINE-CONTROL“);
let m = Method::from_bytes(„BASELINE-CONTROL“);
let is_baseline = match m {
BASELINE_CONTROL => true,
_ => false,
}; will not match. |
I'll add a test for this case and figure out what's wrong. |
Allows creating constant
Method
instances, e.g.:Fixes: #587