tower-rs / tower-http

HTTP specific Tower utilities.
682 stars 159 forks source link

add From<i32> impl for GrpcCode #506

Open gshipilov opened 2 weeks ago

gshipilov commented 2 weeks ago

This change adds a From<i32> impl for the GrpcCode enum. This allows users to easily convert the result of the GrpcErrorsAsFailures back into an enum.

Fixes: #505

Motivation

I recently had to implement a custom TraceLayer on-failure struct, and it made sense to reuse the GrpcErrorsAsFailures class to extract the status. Unfortunately, it returns the error code as a NoneZeroI32 but tower_http doesn't have a convenient way to map this back to the num.

Implementing this is trivial, but still feels like a reasonable addition to this library.

Solution

I feel like this solution is pretty self-explanatory :).