devtools/actors/inspector/
layout.rs1use malloc_size_of_derive::MallocSizeOf;
9use serde::Serialize;
10use serde_json::{Map, Value};
11
12use crate::actor::{Actor, ActorEncode, ActorError, ActorRegistry};
13use crate::protocol::ClientRequest;
14use crate::{ActorMsg, StreamId};
15
16#[derive(MallocSizeOf)]
17pub(crate) struct LayoutInspectorActor {
18 name: String,
19}
20
21#[derive(Serialize)]
22pub(crate) struct GetGridsReply {
23 from: String,
24 grids: Vec<String>,
25}
26
27#[derive(Serialize)]
28pub(crate) struct GetCurrentFlexboxReply {
29 from: String,
30 flexbox: Option<()>,
31}
32
33impl Actor for LayoutInspectorActor {
34 fn name(&self) -> String {
35 self.name.clone()
36 }
37
38 fn handle_message(
44 &self,
45 request: ClientRequest,
46 _registry: &ActorRegistry,
47 msg_type: &str,
48 _msg: &Map<String, Value>,
49 _id: StreamId,
50 ) -> Result<(), ActorError> {
51 match msg_type {
52 "getGrids" => {
53 let msg = GetGridsReply {
54 from: self.name(),
55 grids: vec![],
57 };
58 request.reply_final(&msg)?
59 },
60 "getCurrentFlexbox" => {
61 let msg = GetCurrentFlexboxReply {
62 from: self.name(),
63 flexbox: None,
65 };
66 request.reply_final(&msg)?
67 },
68 _ => return Err(ActorError::UnrecognizedPacketType),
69 };
70 Ok(())
71 }
72
73 fn cleanup(&self, _id: StreamId) {}
74}
75
76impl LayoutInspectorActor {
77 pub fn new(name: String) -> Self {
78 Self { name }
79 }
80}
81
82impl ActorEncode<ActorMsg> for LayoutInspectorActor {
83 fn encode(&self, _: &ActorRegistry) -> ActorMsg {
84 ActorMsg { actor: self.name() }
85 }
86}