Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #[service] macro #3

Closed
wangrunji0408 opened this issue Dec 8, 2021 · 1 comment
Closed

Add #[service] macro #3

wangrunji0408 opened this issue Dec 8, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@wangrunji0408
Copy link
Member

Currently building a server on top of the RPC interface needs a lot boilerplate code:

pub struct Server {...}

impl Server {
    pub fn new() -> Arc<Self> {
        let server = Arc::new(Server {...});
        server.add_rpc_handler();
        server
    }

    // boilerplate!
    fn add_rpc_handler(self: Arc<Self>) {
        let net = NetLocalHandle::current();

        let this = self.clone();
        net.add_rpc_handler(move |req: Ping| {
            let this = this.clone();
            async move { this.ping(req) }
        });
    }

    fn ping(&self, req: Ping) {
        // handle RPC...
    }
}

We hope to provide a procedural macro to make that easy:

#[madsim::service]
impl Server {
    #[ctor]
    pub fn new() -> Arc<Self> {
        Arc::new(Server {...})
    }

    #[rpc]
    fn ping(&self, req: Ping) {
        // handle RPC...
    }
}
@wangrunji0408 wangrunji0408 added the enhancement New feature or request label Dec 8, 2021
@wangrunji0408 wangrunji0408 self-assigned this Dec 9, 2021
@wangrunji0408
Copy link
Member Author

Done in af01015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant