Skip to content

Commit 6483d20

Browse files
committed
fix: added more bounds to rpc types
1 parent d27ecc2 commit 6483d20

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

relay_rpc/src/domain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use {
1212
#[cfg(test)]
1313
mod tests;
1414

15-
#[derive(Debug, thiserror::Error)]
15+
#[derive(Debug, Clone, thiserror::Error)]
1616
pub enum ClientIdDecodingError {
1717
#[error("Invalid issuer multicodec base")]
1818
Base,
@@ -27,7 +27,7 @@ pub enum ClientIdDecodingError {
2727
Length,
2828
}
2929

30-
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
30+
#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
3131
pub enum DecodingError {
3232
#[error("Invalid encoding")]
3333
Encoding,

relay_rpc/src/rpc.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use {
55
crate::domain::{DecodingError, MessageId, SubscriptionId, Topic},
66
serde::{de::DeserializeOwned, Deserialize, Serialize},
7-
std::sync::Arc,
7+
std::{fmt::Debug, sync::Arc},
88
};
99

1010
#[cfg(test)]
@@ -29,7 +29,7 @@ pub const MAX_FETCH_BATCH_SIZE: usize = 500;
2929
type BoxError = Box<dyn std::error::Error + Send + Sync>;
3030

3131
/// Errors covering payload validation problems.
32-
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
32+
#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
3333
pub enum ValidationError {
3434
#[error("Topic decoding failed: {0}")]
3535
TopicDecoding(DecodingError),
@@ -109,14 +109,23 @@ where
109109
}
110110
}
111111

112+
pub trait Serializable:
113+
Debug + Clone + PartialEq + Eq + Serialize + DeserializeOwned + Send + Sync + 'static
114+
{
115+
}
116+
impl<T> Serializable for T where
117+
T: Debug + Clone + PartialEq + Eq + Serialize + DeserializeOwned + Send + Sync + 'static
118+
{
119+
}
120+
112121
/// Trait that adds validation capabilities and strong typing to errors and
113122
/// successful responses. Implemented for all possible RPC request types.
114-
pub trait RequestPayload {
123+
pub trait RequestPayload: Serializable {
115124
/// The error representing a failed request.
116-
type Error: Into<ErrorData>;
125+
type Error: Into<ErrorData> + Send + 'static;
117126

118127
/// The type of a successful response.
119-
type Response: Serialize + DeserializeOwned;
128+
type Response: Serializable;
120129

121130
/// Validates the request parameters.
122131
fn validate(&self) -> Result<(), ValidationError> {

0 commit comments

Comments
 (0)