Skip to content

Commit

Permalink
add From<i32> impl for GrpcCode
Browse files Browse the repository at this point in the history
  • Loading branch information
gshipilov committed Aug 30, 2024
1 parent 3f98dc1 commit 2f73b9a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tower-http/src/classify/grpc_errors_as_failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ impl GrpcCode {
}
}

impl From<i32> for GrpcCode {
fn from(value: i32) -> Self {
match value {
0 => GrpcCode::Ok,
1 => GrpcCode::Cancelled,
2 => GrpcCode::Unknown,
3 => GrpcCode::InvalidArgument,
4 => GrpcCode::DeadlineExceeded,
5 => GrpcCode::NotFound,
6 => GrpcCode::AlreadyExists,
7 => GrpcCode::PermissionDenied,
8 => GrpcCode::ResourceExhausted,
9 => GrpcCode::FailedPrecondition,
10 => GrpcCode::Aborted,
11 => GrpcCode::OutOfRange,
12 => GrpcCode::Unimplemented,
13 => GrpcCode::Internal,
14 => GrpcCode::Unavailable,
15 => GrpcCode::DataLoss,
16 => GrpcCode::Unauthenticated,

_ => GrpcCode::Unknown,
}
}
}

bitflags! {
#[derive(Debug, Clone, Copy)]
pub(crate) struct GrpcCodeBitmask: u32 {
Expand Down

0 comments on commit 2f73b9a

Please sign in to comment.