Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add From<i32> impl for GrpcCode #506

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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