From 222ce1e2bcc6341c46a0b0dcd9a94c3319a1ca45 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Tue, 7 May 2024 18:26:03 +0200 Subject: [PATCH] implement From and From for PubSubItem --- crates/json-rpc/src/notification.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/json-rpc/src/notification.rs b/crates/json-rpc/src/notification.rs index 4b2b61e110f..34f2900bb38 100644 --- a/crates/json-rpc/src/notification.rs +++ b/crates/json-rpc/src/notification.rs @@ -26,6 +26,18 @@ pub enum PubSubItem { Notification(EthNotification), } +impl From for PubSubItem { + fn from(response: Response) -> Self { + PubSubItem::Response(response) + } +} + +impl From for PubSubItem { + fn from(notification: EthNotification) -> Self { + PubSubItem::Notification(notification) + } +} + impl<'de> Deserialize<'de> for PubSubItem { fn deserialize(deserializer: D) -> Result where @@ -94,7 +106,7 @@ impl<'de> Deserialize<'de> for PubSubItem { ) })?; - Ok(PubSubItem::Response(Response { id, payload })) + Ok(Response { id, payload }.into()) } else { // Notifications cannot have an error. if error.is_some() {