Skip to content

devtools: Use register method in actors #43800

@eerii

Description

@eerii

To create an Actor in devtools you need to follow a few steps:

  1. Give it a name, using ActorRegistry::new_name.
  2. Fill the actor struct.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-devtoolsC-assignedThere is someone working on resolving the issueE-less-complexStraightforward. Recommended for a new contributor.good first issueNewcomer-friendly issues.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions