actix-derive icon indicating copy to clipboard operation
actix-derive copied to clipboard

#[derive(Actor)]

Open callym opened this issue 7 years ago • 5 comments

Should we add a custom derive for the Actor trait?

#[derive(Actor)]
struct SumActor;

Which expands to:

impl Actor for SumActor {
    type Context = Context<Self>;
}

callym avatar Nov 16 '17 17:11 callym

main problem is we can have many different contexts. we can use something like #[actor] for default context or #[actor(HttpContext)] in case of custom context. it requires nightly but i think that's fine

fafhrd91 avatar Nov 16 '17 18:11 fafhrd91

@callym are you planing to work on any of the issues?

fafhrd91 avatar Nov 21 '17 18:11 fafhrd91

I think we can do

#[derive(Actor)]
#[derive(Actor)]
#[ActorContext(HttpContext)]

This wouldn't require Nightly as it can be done in custom derive (the same way #[Message(result, error)] is done)

callym avatar Nov 22 '17 19:11 callym

What is the point? Even without macro actor definition takes only 3 lines. I don’t think it worse introducing macro

fafhrd91 avatar Nov 23 '17 21:11 fafhrd91

@fafhrd91 I would really appreciate if we could implement this. "To answer What's the point?" -> The same as for #[ derive( Message )]. It only saves 3 lines per Actor, so in serious project it saves like 300 lines.

As for the context. It seems the same situation as Message with Result, and I would stick to consistent implementation with message, in the lines of: #[ctype=HttpContext]. It doesn't cost anything, but it might shave a few hundred lines of a project. And to be honest, I have alot of actors, but never used another context than default.

najamelan avatar Mar 12 '19 11:03 najamelan