Skip to content

Commit

Permalink
node-data: change EventSource component to be const
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Aug 6, 2024
1 parent e1e9806 commit 11a853e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
9 changes: 5 additions & 4 deletions node-data/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ pub struct Event {
}

pub trait EventSource {
fn component(&self) -> &'static str;
const COMPONENT: &'static str;

fn topic(&self) -> &'static str;
fn entity(&self) -> String;
fn data(&self) -> EventData;
}

impl<B: EventSource> From<B> for Event {
fn from(value: B) -> Self {
impl<ES: EventSource> From<ES> for Event {
fn from(value: ES) -> Self {
Self {
data: value.data(),
topic: value.topic(),
entity: value.entity(),
component: value.component(),
component: ES::COMPONENT,
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions node-data/src/events/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use super::*;
use crate::ledger::{Block, Hash};

impl EventSource for BlockEvent<'_> {
fn component(&self) -> &'static str {
"blocks"
}
const COMPONENT: &'static str = "blocks";

fn topic(&self) -> &'static str {
match self {
Self::Accepted(_) => "accepted",
Expand Down
5 changes: 2 additions & 3 deletions node-data/src/events/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ pub enum TransactionEvent<'t> {
}

impl EventSource for TransactionEvent<'_> {
fn component(&self) -> &'static str {
"transactions"
}
const COMPONENT: &'static str = "transactions";

fn topic(&self) -> &'static str {
match self {
Self::Removed(_) => "removed",
Expand Down

0 comments on commit 11a853e

Please sign in to comment.