To create an Actor in devtools you need to follow a few steps:
- Give it a name, using
ActorRegistry::new_name.
- Fill the actor struct.
- Add it to the
ActorRegistry with the register method.
We have been adding a register method to each actor, that takes an ActorRegistry reference and the necessary parameter, and does the three steps inside. It returns the name, which can always be used to get the actor later with ActorRegistry::find.
There are a few different way we instantiate actors. Some use this pattern, but some have a new method that returns the Actor itself, not it's name, and others are instantiated directly with the struct. Others have different names, like new_registered. There are some long term refactoring ideas that could benefit from this being consistent, so I propose moving to register methods everywhere. The idea is to go from this:
impl TestActor {
pub fn new(name: String) -> Self {
Self { name }
}
}
let test_name = registry.new_name::<TestActor>();
let test_actor = TestActor::new(test_name);
registry.register(test_actor);
To this:
impl TestActor {
pub fn register(registry: &ActorRegistry) -> String {
let name = registry.new_name::<Self>();
let actor = Self { name: name.clone() };
registry.register::<Self>(actor);
name
}
}
let test_name = TestActor::register(registry);
Keep in mind #43606 when changing the function calls. Inside the register function we should keep name and actor without a prefix, since we are already in the context of creating a new Actor, so we know which one it is.
Before submitting a PR, please build the new code and run mach test-devtools to check that nothing has changed.
This is a meta issue, different contributors can work in parallel, so you don't need to assign it to yourself. If you are working one actor, mention them in the description so your work doesn't overlap with others.
To create an
Actorin devtools you need to follow a few steps:ActorRegistry::new_name.ActorRegistrywith theregistermethod.We have been adding a
registermethod to each actor, that takes anActorRegistryreference and the necessary parameter, and does the three steps inside. It returns the name, which can always be used to get the actor later withActorRegistry::find.There are a few different way we instantiate actors. Some use this pattern, but some have a
newmethod that returns theActoritself, not it's name, and others are instantiated directly with the struct. Others have different names, likenew_registered. There are some long term refactoring ideas that could benefit from this being consistent, so I propose moving toregistermethods everywhere. The idea is to go from this:To this:
Keep in mind #43606 when changing the function calls. Inside the
registerfunction we should keepnameandactorwithout a prefix, since we are already in the context of creating a newActor, so we know which one it is.Before submitting a PR, please build the new code and run
mach test-devtoolsto check that nothing has changed.This is a meta issue, different contributors can work in parallel, so you don't need to assign it to yourself. If you are working one actor, mention them in the description so your work doesn't overlap with others.