1use std::fmt;
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5pub enum Bus {
6 Global,
8 Window,
10}
11
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
14pub enum StoreOp {
15 Set,
16 Delete,
17 DeletePrefix,
19}
20
21#[derive(Clone, Debug, PartialEq)]
25pub enum Point {
26 Action { message: &'static str },
28 Send {
30 actor: &'static str,
31 message: &'static str,
32 },
33 Handle {
35 actor: &'static str,
36 message: &'static str,
37 },
38 Spawn {
43 actor: &'static str,
44 actor_id: u64,
45 output: &'static str,
46 },
47 Settled {
49 actor: &'static str,
50 actor_id: u64,
51 output: &'static str,
52 took_us: u64,
53 },
54 Cancelled {
57 actor: &'static str,
58 actor_id: u64,
59 output: &'static str,
60 took_us: u64,
61 },
62 Publish {
64 event: &'static str,
65 bus: Bus,
66 subscribers: usize,
67 },
68 Deliver { event: &'static str, bus: Bus },
70 Push { reducer: &'static str },
72 Navigate { root: String, to: String },
74 Tick { timer: u64 },
77 Store {
79 op: StoreOp,
80 path: String,
81 field: Option<String>,
84 outside: bool,
86 },
87 Render {
90 segment: &'static str,
91 took_us: u64,
92 },
93 Log {
95 level: tracing::Level,
96 target: &'static str,
97 file: Option<&'static str>,
100 line: Option<u32>,
101 module: Option<&'static str>,
102 text: String,
104 },
105 Note(String),
107}
108
109impl Point {
110 pub fn kind(&self) -> &'static str {
112 match self {
113 Point::Action { .. } => "action",
114 Point::Send { .. } => "send",
115 Point::Handle { .. } => "handle",
116 Point::Spawn { .. } => "spawn",
117 Point::Settled { .. } => "settled",
118 Point::Cancelled { .. } => "cancelled",
119 Point::Publish { .. } => "publish",
120 Point::Deliver { .. } => "deliver",
121 Point::Push { .. } => "push",
122 Point::Navigate { .. } => "navigate",
123 Point::Tick { .. } => "tick",
124 Point::Store { .. } => "store",
125 Point::Render { .. } => "render",
126 Point::Log { .. } => "log",
127 Point::Note(_) => "note",
128 }
129 }
130}
131
132impl fmt::Display for Bus {
133 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134 f.write_str(match self {
135 Bus::Global => "global",
136 Bus::Window => "window",
137 })
138 }
139}
140
141impl fmt::Display for StoreOp {
142 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
143 f.write_str(match self {
144 StoreOp::Set => "set",
145 StoreOp::Delete => "delete",
146 StoreOp::DeletePrefix => "delete_prefix",
147 })
148 }
149}
150
151impl fmt::Display for Point {
152 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153 match self {
154 Point::Action { message } => write!(f, "action {message}"),
155 Point::Send { actor, message } => write!(f, "send {message} → {actor}"),
156 Point::Handle { actor, message } => write!(f, "{actor} handles {message}"),
157 Point::Spawn { actor, output, .. } => write!(f, "{actor} starts work for {output}"),
158 Point::Settled {
159 actor,
160 output,
161 took_us,
162 ..
163 } => write!(
164 f,
165 "{actor} has its {output} after {:.1} ms",
166 *took_us as f64 / 1000.0
167 ),
168 Point::Cancelled {
169 actor,
170 output,
171 took_us,
172 ..
173 } => write!(
174 f,
175 "{actor} is gone: {output} cancelled after {:.1} ms",
176 *took_us as f64 / 1000.0
177 ),
178 Point::Publish {
179 event,
180 bus,
181 subscribers,
182 } => write!(f, "publish {event} on the {bus} bus to {subscribers}"),
183 Point::Deliver { event, bus } => write!(f, "deliver {event} from the {bus} bus"),
184 Point::Push { reducer } => write!(f, "push into {reducer}"),
185 Point::Navigate { root, to } => write!(f, "{root} navigates to {to}"),
186 Point::Tick { timer } => write!(f, "timer #{timer}"),
187 Point::Render { segment, took_us } => {
188 write!(f, "{segment} drew itself in {:.1} ms", *took_us as f64 / 1000.0)
189 }
190 Point::Store {
191 op,
192 path,
193 field,
194 outside,
195 } => {
196 let who = if *outside { "disk" } else { "store" };
197 let verb = match op {
198 StoreOp::Set => "sets",
199 StoreOp::Delete => "deletes",
200 StoreOp::DeletePrefix => "clears",
201 };
202 write!(f, "{who} {verb} {path}")?;
203 match field {
204 Some(field) => write!(f, " ({field})"),
205 None => Ok(()),
206 }
207 }
208 Point::Log {
209 level,
210 target,
211 text,
212 ..
213 } => write!(f, "{level} {target}: {text}"),
214 Point::Note(text) => f.write_str(text),
215 }
216 }
217}