-
Notifications
You must be signed in to change notification settings - Fork 124
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
what's the best way to test/match Method objects #86
Comments
There's an |
Thanks, .equiv will be handy! Do you think it's not too late to replace Method with an enum and do you think that would be better? I'm rewriting an http server I originally wrote in C to provide an http interface to a PostgreSQL database. In my C server I use enums for methods and for the standard request and respond header names (but adding an "other" case so I can pass along any non-standard header-names). |
I like the idea of making it an enum, what do you think @tomaka? Hyper does something similar |
There are several good places where an enum might work better than a struct, including: request method, http version, request header names and response header names. I love Rust's ability for enum constructors to take a parameter so that an enum type can be made open by providing an "other" constructor which takes a string value. |
+1 for enums. Strings can also lead to typos with no compilation error to tell you made one; whereas if you spell an enumeration value wrong, the compiler will spit an error at you. |
I think that Hyper is repeating itself a bit here, specifically they're giving the same set of strings in their as_ref and from_str methods. I think it would be easier to just make an array of the string values indexed by the integer value of the enums. This pattern can be reused to similarly implement request header names and response header names. |
Opened a PR that addresses this: #102 |
Feedback is greatly appreciated ;) |
I'm finding it awkward to construct and test Method objects. I've found myself doing clumsy things like:
is there a simpler way to construct and/or test values of type Method?
It seems to me that modelling type Method as an enum might be simpler, easier and more efficient. Am I missing something?
Still loving tiny-http! _Greg
The text was updated successfully, but these errors were encountered: