Closed nebneb0703 closed 2 years ago
Implements the topic macro from #4
example syntax is shown already in network/src/topics.rs
network/src/topics.rs
define_topics! { Coordinator { #[message = AuthNodeInit] Auth -> "coordinator/auth" }, Node { Auth -> "node/{id}/auth" } }
generates:
pub enum Topic { Coordinator(CoordinatorTopic), Node(NodeTopic), } pub struct CoordinatorAuthTopic; impl CoordinatorAuthTopic { pub fn topic(&self) -> String { "coordinator/auth".to_owned() } pub fn message(&self) -> AuthNodeInit { Default::default() } } pub enum CoordinatorTopic { Auth, } pub struct NodeAuthTopic; impl NodeAuthTopic { pub fn topic(&self, id: String) -> String { format!("node/{id}/auth") } } pub enum NodeTopic { Auth, } macro_rules! topic { (Coordinator::Auth) => { CoordinatorAuthTopic }; (Node::Auth) => { NodeAuthTopic }; }
should probably add some docs to the macro before merging
very nice~
Implements the topic macro from #4
example syntax is shown already in
network/src/topics.rs
generates: