slawlor / ractor

Rust actor framework
MIT License
1.3k stars 66 forks source link

Enum contains type of itself #208

Closed zrus closed 4 months ago

zrus commented 4 months ago

Describe the bug Unexpected argument of type RpcReplyPort<_> when implement an enum that one of its variants contains type of itself.

To Reproduce I have an enum that is:

pub enum Command {
  Get(String, RpcReplyPort<String>),
  Delete(String, RpcReplyPort<String>),
  Retry(Box<Command>, u8),
}

Expected behavior Success on handling upcoming command in handle method from Actor trait.

Additional context Rust v1.75, lib v0.9.6

slawlor commented 4 months ago

What is the problem with this? You're failing to compile?

zrus commented 4 months ago

Yes. I missed a picture of it. Let me put it here.

error[E0061]: this enum variant takes 2 arguments but 3 arguments were supplied
   --> src/http_cli.rs:85:21
    |
85  |           call!(me, HttpCliCommand::Retry, *cmd, time);
    |           ----------^^^^^^^^^^^^^^^^^^^^^------------- unexpected argument of type `RpcReplyPort<_>`
    |
note: tuple variant defined here
   --> src/http_cli.rs:104:3
    |
104 |   Retry(Box<HttpCliCommand>, u8),
    |   ^^^^^
slawlor commented 4 months ago

That's because the call! macro is expecting the last argument of the tuple of arguments to be the reply channel to send the reply on. If you actually want this pattern to work, you will have to handle piping the reply channel from the boxed internal struct. Theoretically the way you've written it you could have retry nested n-deep and there's no way for the macro to desugar that.

Essentially the macro won't work here and there isn't a solution to make it work. You'll have to do it by hand using ActorRef<_>::call

zrus commented 4 months ago

Sorry, my bad. I actually need to use .send_massage instead of call! macro. Thanks for your reply.