Skip to content

Commit d234d3e

Browse files
committed
Add a new requirements trait LocalRpcMessage
The idea is to use this instead of manual bounds so it is easier to configure required bounds based on feature flags.
1 parent 1168865 commit d234d3e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,27 @@ pub mod util;
8787
#[cfg(not(feature = "rpc"))]
8888
mod util;
8989

90+
/// Requirements for a local RPC message.
91+
///
92+
/// Local RPC messages must be Send and Sync so they can be sent between
93+
/// threads, but they don't have to be serializable. They can not be serializable
94+
/// since they contain channels.
95+
///
96+
/// In addition we require Debug for convenience.
97+
pub trait LocalRpcMessage: Debug + Send + Sync + Unpin + 'static {}
98+
99+
impl<T> LocalRpcMessage for T where T: Debug + Send + Sync + Unpin + 'static {}
100+
90101
/// Requirements for a RPC message
91102
///
92103
/// Even when just using the mem transport, we require messages to be Serializable and Deserializable.
93104
/// Likewise, even when using the quinn transport, we require messages to be Send.
94105
///
95106
/// This does not seem like a big restriction. If you want a pure memory channel without the possibility
96107
/// to also use the quinn transport, you might want to use a mpsc channel directly.
97-
pub trait RpcMessage: Debug + Serialize + DeserializeOwned + Send + Sync + Unpin + 'static {}
108+
pub trait RpcMessage: LocalRpcMessage + Serialize + DeserializeOwned {}
98109

99-
impl<T> RpcMessage for T where
100-
T: Debug + Serialize + DeserializeOwned + Send + Sync + Unpin + 'static
101-
{
102-
}
110+
impl<T> RpcMessage for T where T: LocalRpcMessage + Serialize + DeserializeOwned {}
103111

104112
/// Marker trait for a service
105113
///

0 commit comments

Comments
 (0)