Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

More advanced macros #2

@callym

Description

@callym

I implemented a #[handler] macro to allow you to tag functions as a handler for a type, and generate the necessary code implementing the Handler trait for the type.
Is this useful?

It'd require Nightly because it depends on feature(proc_macro), but that can be feature-gated, so the custom derives would still work on Stable.

#[handler]
impl SumActor {
    #[handle(Sum)]
    fn sum(&mut self, message: Sum, _: &mut Context<Self>) -> Response<Self, Sum> {
        println!("{}", message.0 + message.1);
        Self::reply(message.0 + message.1)
    }
}

Which would expand to:

impl SumActor {
    fn sum(&mut self, message: Sum, _: &mut Context<Self>) -> Response<Self, Sum> {
        println!("{}", message.0 + message.1);
        Self::reply(message.0 + message.1)
    }
}

impl Handler<Sum> for SumActor {
    fn handle(&mut self, message: Sum, context: &mut Context<Self>) -> Response<Self, Sum> {
        self.sum(message, context)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions