Skip to content

Commit

Permalink
implement From<Response> and From<EthNotification> for PubSubItem (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed May 7, 2024
1 parent e4c5756 commit 952632b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/json-rpc/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ pub enum PubSubItem {
Notification(EthNotification),
}

impl From<Response> for PubSubItem {
fn from(response: Response) -> Self {
PubSubItem::Response(response)
}
}

impl From<EthNotification> for PubSubItem {
fn from(notification: EthNotification) -> Self {
PubSubItem::Notification(notification)
}
}

impl<'de> Deserialize<'de> for PubSubItem {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 952632b

Please sign in to comment.