chridou / http-api-problem

A problem type to be returned by HTTP APIs
Apache License 2.0
53 stars 12 forks source link

add `From<std::convert::Infallible>` impls #47

Closed SohumB closed 1 year ago

SohumB commented 1 year ago

std uses std::convert::Infallible to indicate cases where an error is expected but can't happen; in particular, it auto-implements TryFrom for all From implementations, with the error type marked as std::convert::Infallible. It's currently implemented as an enum with no variants, so it's statically impossible to create an instance of.

In code that is attempting to be generic over TryFrom implementations, then, you may need to end up proving From<Infallible> for YourErrorType. This is trivial to implement — the rust compiler understands that it's impossible to ever be handed an instance of an enum with zero variants — but due to coherence rules, the impl needs to live next to YourErrorType. In this case, that means it needs to live in http-api-problem.

Thanks.