quic_rpc/message.rs
1//! Service definition
2//!
3//! Traits to define the behaviour of messages for services
4use std::fmt::Debug;
5
6pub use crate::pattern::{
7 bidi_streaming::{BidiStreaming, BidiStreamingMsg},
8 client_streaming::{ClientStreaming, ClientStreamingMsg},
9 rpc::{Rpc, RpcMsg},
10 server_streaming::{ServerStreaming, ServerStreamingMsg},
11};
12use crate::Service;
13
14/// Declares the interaction pattern for a message and a service.
15///
16/// For each server and each message, only one interaction pattern can be defined.
17pub trait Msg<S: Service>: Into<S::Req> + TryFrom<S::Req> + Send + 'static {
18 /// The interaction pattern for this message with this service.
19 type Pattern: InteractionPattern;
20}
21
22/// Trait defining interaction pattern.
23///
24/// Currently there are 4 patterns:
25/// - [Rpc]: 1 request, 1 response
26/// - [ClientStreaming]: 1 request, stream of updates, 1 response
27/// - [ServerStreaming]: 1 request, stream of responses
28/// - [BidiStreaming]: 1 request, stream of updates, stream of responses
29///
30/// You could define your own interaction patterns such as OneWay.
31pub trait InteractionPattern: Debug + Clone + Send + Sync + 'static {}