profi248 / pluto

[in development] Easily make encrypted backups to other users, in exchange just for your unused disk space!
GNU General Public License v3.0
3 stars 0 forks source link

Topics #6

Closed nebneb0703 closed 2 years ago

nebneb0703 commented 2 years ago

Implements the topic macro from #4

example syntax is shown already in 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 };
}
nebneb0703 commented 2 years ago

should probably add some docs to the macro before merging

profi248 commented 2 years ago

very nice~