-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Place
StatusExt
and RpcStatusExt
into separate files.
Also does some minor module imports cleanup. The goal is to make room for a `CodeExt` trait.
- Loading branch information
Showing
18 changed files
with
1,103 additions
and
1,109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use prost::{ | ||
bytes::{Bytes, BytesMut}, | ||
DecodeError, Message, | ||
}; | ||
use prost_types::Any; | ||
use tonic::Code; | ||
|
||
use crate::pb; | ||
|
||
pub(super) trait IntoAny { | ||
fn into_any(self) -> Any; | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(super) trait FromAny { | ||
fn from_any(any: Any) -> Result<Self, DecodeError> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
pub(super) trait FromAnyRef { | ||
fn from_any_ref(any: &Any) -> Result<Self, DecodeError> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
pub(super) fn gen_details_bytes(code: Code, message: &str, details: Vec<Any>) -> Bytes { | ||
let status = pb::Status { | ||
code: code as i32, | ||
message: message.to_owned(), | ||
details, | ||
}; | ||
|
||
let mut buf = BytesMut::with_capacity(status.encoded_len()); | ||
|
||
// Should never panic since `buf` is initialized with sufficient capacity | ||
status.encode(&mut buf).unwrap(); | ||
|
||
buf.freeze() | ||
} |
Oops, something went wrong.