devtools/actors/
blackboxing.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use malloc_size_of_derive::MallocSizeOf;
6
7use crate::ActorMsg;
8use crate::actor::{Actor, ActorEncode, ActorRegistry};
9
10#[derive(MallocSizeOf)]
11pub(crate) struct BlackboxingActor {
12    name: String,
13}
14
15impl Actor for BlackboxingActor {
16    fn name(&self) -> String {
17        self.name.clone()
18    }
19}
20
21impl BlackboxingActor {
22    pub fn register(registry: &ActorRegistry) -> String {
23        let name = registry.new_name::<Self>();
24        let actor = Self { name: name.clone() };
25        registry.register::<Self>(actor);
26        name
27    }
28}
29
30impl ActorEncode<ActorMsg> for BlackboxingActor {
31    fn encode(&self, _: &ActorRegistry) -> ActorMsg {
32        ActorMsg { actor: self.name() }
33    }
34}