1pub use async_trait::async_trait;
2pub use bitcode;
3
4pub use bitrpc_macros::service;
5
6use bitcode::{Decode, Encode};
7
8#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)]
9pub enum RpcError {
10 Handler { message: String },
11 Decode { message: String },
12 Transport { message: String },
13 Unexpected { expected: String, actual: String },
14}
15
16pub type Result<T, E = RpcError> = core::result::Result<T, E>;
17
18impl RpcError {
19 pub fn handler(message: impl Into<String>) -> Self {
20 Self::Handler {
21 message: message.into(),
22 }
23 }
24
25 pub fn decode(message: impl Into<String>) -> Self {
26 Self::Decode {
27 message: message.into(),
28 }
29 }
30
31 pub fn transport(message: impl Into<String>) -> Self {
32 Self::Transport {
33 message: message.into(),
34 }
35 }
36
37 pub fn unexpected(expected: impl Into<String>, actual: impl Into<String>) -> Self {
38 Self::Unexpected {
39 expected: expected.into(),
40 actual: actual.into(),
41 }
42 }
43}
44
45impl std::fmt::Display for RpcError {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 write!(f, "{:?}", self)
48 }
49}
50
51impl From<bitcode::Error> for RpcError {
52 fn from(err: bitcode::Error) -> Self {
53 Self::Decode {
54 message: err.to_string(),
55 }
56 }
57}
58
59impl std::error::Error for RpcError {}
60
61#[async_trait(?Send)]
62pub trait RpcTransport {
63 async fn call(&mut self, request: Vec<u8>) -> Result<Vec<u8>>;
64}
65
66pub type DecodeError = bitcode::Error;
67
68#[cfg(feature = "cyper")]
69pub mod cyper;
70
71#[cfg(feature = "compio-quic")]
72pub mod compio_quic;
73
74#[cfg(feature = "compio-server")]
75mod bufferpool;
76
77#[cfg(feature = "compio-server")]
78pub mod compio_server;
79#[cfg(feature = "compio-server")]
80pub use compio_server::{RpcRequestService, ServerBuilder};