Skip to content

Commit

Permalink
fix: move macro to macro.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
luketchang committed Feb 11, 2022
1 parent c4ab6b1 commit 5f957c5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 69 deletions.
14 changes: 12 additions & 2 deletions nomad-base/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::{
cancel_task,
metrics::CoreMetrics,
settings::{IndexSettings, Settings},
BaseError, CachingHome, CachingReplica, ChannelBase, ContractSyncMetrics, IndexDataTypes,
NomadDB,
BaseError, CachingHome, CachingReplica, ContractSyncMetrics, IndexDataTypes, NomadDB,
};
use async_trait::async_trait;
use color_eyre::{eyre::WrapErr, Result};
Expand Down Expand Up @@ -36,6 +35,17 @@ pub struct AgentCore {
pub settings: crate::settings::Settings,
}

#[derive(Debug, Clone)]
/// Commmon data needed for a single agent channel
pub struct ChannelBase {
/// Home
pub home: Arc<CachingHome>,
/// Replica
pub replica: Arc<CachingReplica>,
/// NomadDB keyed by home
pub db: NomadDB,
}

/// A trait for an application:
/// that runs on a replica
/// and:
Expand Down
64 changes: 0 additions & 64 deletions nomad-base/src/channel.rs

This file was deleted.

3 changes: 0 additions & 3 deletions nomad-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ pub use settings::*;
mod agent;
pub use agent::*;

mod channel;
pub use channel::*;

#[doc(hidden)]
#[cfg_attr(tarpaulin, skip)]
#[macro_use]
Expand Down
51 changes: 51 additions & 0 deletions nomad-base/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,57 @@ macro_rules! decl_agent {
};
}

#[macro_export]
/// Declare a new channel block
/// ### Usage
///
/// ```ignore
/// decl_channel!(Relayer {
/// updates_relayed_counts: prometheus::IntCounterVec,
/// interval: u64,
/// });
/// ```
macro_rules! decl_channel {
(
$name:ident {
$($(#[$tags:meta])* $prop:ident: $type:ty,)*
}
) => {
paste::paste! {
#[derive(Debug, Clone)]
#[doc = "Channel for `" $name]
pub struct [<$name Channel>] {
pub(crate) base: nomad_base::ChannelBase,
$(
$(#[$tags])*
pub(crate) $prop: $type,
)*
}

impl AsRef<nomad_base::ChannelBase> for [<$name Channel>] {
fn as_ref(&self) -> &nomad_base::ChannelBase {
&self.base
}
}

impl [<$name Channel>] {
pub fn home(&self) -> Arc<CachingHome> {
self.as_ref().home.clone()
}

pub fn replica(&self) -> Arc<CachingReplica> {
self.as_ref().replica.clone()
}

pub fn db(&self) -> nomad_base::NomadDB {
self.as_ref().db.clone()
}
}
}
}
}

#[macro_export]
/// Declare a new settings block
///
Expand Down

0 comments on commit 5f957c5

Please sign in to comment.