3 ms·
What's the benefit of having a State type, instead of using handle(&mut self), pre_start() -> Self, and putting the state inside the type that implements the ac
by whytevuhuni 2y ago
What's the benefit of having a State type, instead of using handle(&mut self), pre_start() -> Self, and putting the state inside the type that implements the actor?
- derefr 2y agoFrom the README (https://github.com/slawlor/ractor?tab=readme-ov-file#differences-between-an-actors-state-and-self https://github.com/slawlor/ractor?tab=readme-ov-file#differe...): > When designing ractor, we made the explicit decision to make a separate state type for an actor, rather than passing around a mutable self reference. The reason for this is that if we were to use a &mut self reference, creation + instantiation of the Self struct would be outside of the actor's specification (i.e. not in pre_start) and the safety it gives would be potentially lost, causing potential crashes in the caller when it maybe shouldn't. > Lastly is that we would need to change some of the ownership properties that ractor is currently based on to pass an owned self in each call, returning a Self reference which seems clunky in this context.