Hacker News new | past | comments | ask | show | jobs | submit login

Great start. Instead of numeric codes, perhaps use an enum for all the acceptable status codes?

As Jane Street Says, make illegal state unrepresentable.




This 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.


Good 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.



My 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.


No worries! I just meant to confirm your suspicions :)


And 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: