Actor upcasting/downcasting #41
Replies: 2 comments
-
|
Ah it looks like |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the references to Handling a DOM as actors seems interesting although slightly inefficient if calls have to cascade down the tree. I guess the point of using actors is to not look at the DOM as a static data structure, but rather as a living thing that has to respond to events and changes. It's an interesting idea. I wonder whether the actor separation may complicate things, i.e. actors can't peer into other actors' state. So if you need to know something about a parent or child, you'd have to call them asynchronously. With The other alternative listed on my page is to make the trait external. Then you definitely can do downcasting. But it is more awkward in the code. I guess the purpose of up/downcasting is to have an actor which optionally implements a whole set of different APIs. So what you really want is to be able to specify both the trait and the method, i.e. execute this method from this trait on this struct. It may be that the actor doesn't implement that method, in which case it would do nothing or return an error. This problem is actually independent from the actor system. If you can create a "dispatcher" trait that does this job, of being able to attempt to run any method from any trait on a struct, then you could put it in an actor and it would work the same. So So you'd create an |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! Fantastic crate, huge fan of the API and the similarities to projects like PonyLang!
I hate to resurrect a topic that's been beaten to death but I've been trying to figure out a way around this situation I've gotten myself into. For some background, I've convinced myself that a DOM implementation (and corresponding webview) is a Good Idea to try and implement in an actor based approach where each element in the dom is an actor instance. So far it's been an interesting mental puzzle so I'll just say it straight that I'm interested in this from a toy project perspective, rather than from a work perspective. That is to say, if the work or thought to answer this turns out to be incredibly complicated, feel free to tell me to shove off :)
So as you might know, the DOM is heavily specced out by C++ inheritance hierarchies due to projects like Chrome and Firefox. Servo has gotten around inheritance and rust limitations by doing some mem::transmute calls and repr(c). My brain tends to try and work more on the composing behaviors front due to a large amount of OOP in my day job, so my instincts tell me that I need a lot of traits.
Putting code down:
As you can see a
Nodehas two pointers to the head/tail of its children. There are other pointers here for siblings to form a doubly linked list, omitted for brevity. ANodecan have a child that is a) a text node, b) an html element, c) an svg element, etc etc, hence the usage of an erased type.I've attempted to try and distill this down to something a bit more static but it's eluding me at the moment, so my current idea is that of casting between traits to coerce an
dyn ActsAsNodeinto andyn ActsAsElement, but you already know that doesn't work given rust's blocking issues with CoerceUnsized, upcasting, and unsized enum variants.I suppose this is more of a general question aimed at figuring out what my options are, is this something that could (in theory) be supported by Stakker on stable or is this fundamentally not possible due to the blocking rust issues? I've found https://docs.rs/unsize/latest/unsize/ which purportedly brings unsized coercion to stable, but I don't know enough about unstable rust to vet its abilities.
Beta Was this translation helpful? Give feedback.
All reactions