hyperium / http

Rust HTTP types
Apache License 2.0
1.12k stars 283 forks source link

Add Method::from_static #595

Open WhyNotHugo opened 1 year ago

WhyNotHugo commented 1 year ago

Allows creating constant Method instances, e.g.:

const PROPFIND: Method = Method::from_static(b"PROPFIND");

Fixes: https://github.com/hyperium/http/issues/587

WhyNotHugo commented 1 year ago

Oh, I just realised that CI failed due to panic! not being available on the MSRV. I'll try refactoring that.

seanmonstar commented 1 year ago

We could probably update the MSRV, depending on what the version required is and how old it is.

WhyNotHugo commented 1 year ago

Rust 1.57.0, from 2021-12-02

WhyNotHugo commented 1 year ago

For tokio, the current MSRV is 1.56.0.

WhyNotHugo commented 1 year ago

I've updated the PR to panic without panic!. I used ([] as [u8; 0])[0];, which is already used as a const panic! hack in a couple of other places in the codebase.

We can remove this hack (both this new instance and existing ones) once the MSRV is bumped to 1.57.0 or greater.

lperlaki commented 9 months ago

I was wondering if we could add a variant StaticRef(&'static [u8]) to the Method Inner enum instead of panicking on longer than 15 byte methods?

WhyNotHugo commented 9 months ago

I don't know of any methods that are longer than 15 bytes, so I'm not sure that it's worth the effort.

2xsaiko commented 5 months ago

What's this stuck on?

lperlaki commented 5 months ago

I would also like to see this being merged as it helps with implementing a webdav server base on hyper

I don't know of any methods that are longer than 15 bytes, so I'm not sure that it's worth the effort.

recently I stubbled over the BASELINE-CONTROL webdav method wich is longe than 15 bytes (16)

I was wondering if we could add a variant StaticRef(&'static [u8]) to the Method Inner enum instead of panicking on longer than 15 byte methods?

figured out that this wouldn't work with the current implementation since the equality also checks the enum variant wich is required that Method can support pattern matching