Skip to content

Conversation

gshipilov
Copy link

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 :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement From<NonZeroI32> for GrpcCode
1 participant