riker-rs / riker

Easily build efficient, highly concurrent and resilient applications. An Actor Framework for Rust.
https://riker.rs
MIT License
1.02k stars 69 forks source link

Derive receive for actors with generic arguments. #121

Closed olanod closed 4 years ago

olanod commented 4 years ago

Hi! I have an Actor that is generic over a type and when using the macro #[actor(SomeMsg)] the compiler complains with wrong number of type arguments: expected 1, found 0 expected 1 type argument.

#[actor(SomeMsg)]
struct MyActor<T> {
    foo: T,
}
// ... generates
impl Receive<MyActorMsg> for MyActor { ... }

Doesn't seem like a big issue to fix but I haven't worked with procedural macros, I might try later but if anyone knows how to feel free to jump in :)

igalic commented 4 years ago

is this possibly related to https://github.com/riker-rs/riker/pull/100 ?

hardliner66 commented 4 years ago

@igalic No, this is about the generic part of the user-struct and not about the Receive trait. The derive macro ignores the generic type parameters.

leenozara commented 4 years ago

In procedural macros the type being "expanded" is represented by proc_macros::Ident and that doesn't seem to capture the generic component - or at least I had trouble doing so when I wrote the macro. Documentation isn't great, but once once you get the DSL it is fairly straight forward.

https://github.com/riker-rs/riker/blob/master/src/actor/channel.rs is an example of implementing the trait manually without the macro, if you need to get your application working urgently.

hardliner66 commented 4 years ago

I already tried to fix this. There is an example inside the sync documentation: https://docs.rs/syn/1.0.33/syn/struct.Generics.html#method.split_for_impl

Sadly just following that example still won’t compile because a type parameter is missing somewhere. I’ll try again today.