http-rs / http-types

Common types for HTTP operations
https://docs.rs/http-types
Apache License 2.0
200 stars 84 forks source link

add PartialEq between &StatusCode and u16 #319

Closed jbr closed 3 years ago

yoshuawuyts commented 3 years ago

StatusCode is a thin wrapper around u16, and implements Clone. Simply dereferencing one side, or borrowing another should already work in all cases right?

assert_eq!(*status, 400);
assert_eq!(status, &400);
joshtriplett commented 3 years ago

I think we should maintain the distinction between these two types, since it's not especially difficult to dereference StatusCode when comparing it. Is there a use case where that makes code substantially more onerous?

jbr commented 3 years ago

It's been a bit since I needed this, but I believe it was either for matching or for equality testing between nested types like Option<&StatusCode> without having to .as_deref(). Not critically important, but more convenient

yoshuawuyts commented 3 years ago

Oh, if we have an API anywhere here which returns Option<&u16> we should def change it to be Option<u16> instead. @jbr did you recall whether this was in an http-rs library?

jbr commented 3 years ago

It wasn't in http-rs. The function was returning Option<&StatusCode> and it was convenient to be able to test equality Some(200) or whatever. The other PartialEq was just for parity. Not important behavior, I just didn't see any downside