request_response/request.rs
1//! This file contains the [`Request`] and [`Response`] traits. Any upstream
2//! that wants to use the [`RequestResponseProtocol`] needs to implement these
3//! traits for their specific types.
4
5use std::fmt::Debug;
6
7use anyhow::Result;
8
9use super::Serializable;
10
11/// A trait for a request. Associates itself with a response type.
12#[cfg(not(test))]
13pub trait Request: Send + Sync + Serializable + 'static + Clone + Debug {
14 /// The response type associated with this request
15 type Response: Send + Sync + Serializable + Clone + Debug;
16
17 /// Validate the request, returning an error if it is not valid
18 ///
19 /// # Errors
20 /// If the request is not valid
21 fn validate(&self) -> Result<()>;
22}
23
24/// A trait for a request. Associates itself with a response type.
25#[cfg(test)]
26pub trait Request: Send + Sync + Serializable + 'static + Clone + Debug {
27 /// The response type associated with this request
28 type Response: Send + Sync + Serializable + Clone + Debug + PartialEq + Eq;
29
30 /// Validate the request, returning an error if it is not valid
31 ///
32 /// # Errors
33 /// If the request is not valid
34 fn validate(&self) -> Result<()>;
35}