4 ms·
Great start. Instead of numeric codes, perhaps use an enum for all the acceptable status codes? As Jane Street Says, make illegal state unrepresentable.
by maxcan 11y ago
Great start. Instead of numeric codes, perhaps use an enum for all the acceptable status codes?
As Jane Street Says, make illegal state unrepresentable.
- steveklabnik 11y agoThis is a good slogan, but there's some subtleties when it comes to HTTP status codes. That is, there are the defined ones, but any number is legit, so you end up with an enum with a member that's basically "anything we don't know about", so it's not as clear-cut as it is in other situations.
- eridius 11y agoAnd of course a problem with this is any status code now has two representations: the canonical enum variant, and the catch-all variant with the same numeric value.
- maxcan 11y agoGood point, this is where Rust's flexible enums are an advantage relative to C-style. If you'll forgive the Haskell syntax, you can have something like: data StatusCoode = Ok200 | Missing404 | Error500 | OtherStatusCode Int To rephrase the slogan a bit - make an illegal state a bit more difficult to represent or at least the risk of an illegal state clear to the programmer.
- steveklabnik 11y agoExactly: https://github.com/hyperium/hyper/blob/master/src/status.rs#L31-L221 https://github.com/hyperium/hyper/blob/master/src/status.rs#...
- maxcan 11y agoMy bad.. I was just basing my comment off the readme. In general, I love what you guys are doing and my team is looking closely at Rust and Leaf.
- steveklabnik 11y agoNo worries! I just meant to confirm your suspicions :)