Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is nuts: https://www.phind.com/search?cache=30e24cdb-ff4b-4f4d-a748-4.... It understands how to convert between two similar but ultimately incompatible types. It's mostly spot on. The status code conversion to u16 is unnecessary but it does work. There's a more concise way to get a HeaderName from a String: `HeaderName::try_from(string)`, and ultimately the code is more simple and straightforward when using the ResponseBuilder type, but the code works using only the types involved in the query.

What's crazy about this is that it's not a trivial problem. The engine correctly identifies that it's converting http responses and that for the conversion to be meaningful you need to copy the status code, headers, and body. It also correctly identifies that adding multiple headers of the same value is semantically the same as a header with multiple values. I'm pretty sure this example does not appear anywhere in the source material (these are lesser-known crates, not the popular http ones). This is really neat!



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

Search: