Replies: 7 comments
-
I'm trying to figure out what you're trying to do. Do you want both The current actor code is designed around static types. Where we need dynamic glue (e.g. callbacks) it is solved in Stakker using However, I can imagine situations where someone might want to have an actor own one of a class of child actors without knowing the exact type. So this is a dynamic type, rather than a statically-known type. Rust uses the Rust does magic around However, this can probably be solved with some glue, getting things into the right place for Rust to do its coercion magic on a type it knows how to coerce. So below is an example that does what you want. However I still don't think that this is the right way to approach the problem in Rust. There are much quicker ways of implementing the algorithm without using dynamic types, for example using an enum containing all the different options for example.
|
Beta Was this translation helpful? Give feedback.
-
Do any other Rust actor systems allow dynamic references to actors by trait? I might have another go at finding a better solution at the weekend. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the detailed response. I'll get back to you next week. |
Beta Was this translation helpful? Give feedback.
-
After some investigation, there is a fundamental problem. If I do However, I think it can be done (safely) in unsafe Rust. It's a pretty big change, though. There are two workarounds:
Anyway, this will take a while to decide. In any case it means I can't implement this with the "no-unsafe" feature, which is not so good. So maybe I won't put it in. But still making For now, there are some techniques you can use to work around the problem:
The second option means having to decide who owns the actor. You could keep all ownership at the top level, or else if you wish to pass ownership to the actor that will do the calling, you need a wrapper that owns the actor without knowing which actor it is exactly. So this is a variation on the "external dyn" code above:
Maybe I could add So in summary, I think yes it is valid in general to want Thanks for the question! It was a good one. I will write it up in a FAQ I'm preparing. Reply here if you have any more info on the subject. When you think this is done, we can close the issue. |
Beta Was this translation helpful? Give feedback.
-
Thanks to various people in users.rust-lang.org, things are clearer now. Stable enums can't support However there is another workaround that would let you write trait-based actors, that works out quite neatly. There's an example in the discussion comments. So I'm going to create issues for two new features: One for the macro to help create these trait-based actors, and another for |
Beta Was this translation helpful? Give feedback.
-
Okay, I've implemented those two features now in version 0.1.2: |
Beta Was this translation helpful? Give feedback.
-
Hi Jim,
I've been trying out several actor model implementations, include Stakker, and wasn't able to figure out how to refer to an actor that implements a trait.
https://github.com/anacrolix/eratosthenes/blob/8bdb8c9ed5bd9e924bd483e2f480dd87f9fc7359/rust/stakker/src/main.rs#L104
On that line, I want to initialize a
Link
, with aPrinter
, instead of another Link, but I get this error:I expect it has to do with
Link::next
, which is of typeActorOwn<Link>
. Actually I'm happy with a reference to an actor that merely implementsNext
, but I'm not sure how I'd go about expressing that. (I don't thinkActorOwn<Next>
) will work.To experiment with it, checkout that repo, and run
cargo check
inrust/stakker
.Beta Was this translation helpful? Give feedback.
All reactions