use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Bus {
Global,
Window,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum StoreOp {
Set,
Delete,
DeletePrefix,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Point {
Action { message: &'static str },
Send {
actor: &'static str,
message: &'static str,
},
Handle {
actor: &'static str,
message: &'static str,
},
Spawn {
actor: &'static str,
actor_id: u64,
output: &'static str,
},
Settled {
actor: &'static str,
actor_id: u64,
output: &'static str,
took_us: u64,
},
Cancelled {
actor: &'static str,
actor_id: u64,
output: &'static str,
took_us: u64,
},
Publish {
event: &'static str,
bus: Bus,
subscribers: usize,
},
Deliver { event: &'static str, bus: Bus },
Push { reducer: &'static str },
Navigate { root: String, to: String },
Tick { timer: u64 },
Store {
op: StoreOp,
path: String,
field: Option<String>,
outside: bool,
},
Render {
segment: &'static str,
took_us: u64,
},
Log {
level: tracing::Level,
target: &'static str,
file: Option<&'static str>,
line: Option<u32>,
module: Option<&'static str>,
text: String,
},
Note(String),
}
impl Point {
pub fn kind(&self) -> &'static str {
match self {
Point::Action { .. } => "action",
Point::Send { .. } => "send",
Point::Handle { .. } => "handle",
Point::Spawn { .. } => "spawn",
Point::Settled { .. } => "settled",
Point::Cancelled { .. } => "cancelled",
Point::Publish { .. } => "publish",
Point::Deliver { .. } => "deliver",
Point::Push { .. } => "push",
Point::Navigate { .. } => "navigate",
Point::Tick { .. } => "tick",
Point::Store { .. } => "store",
Point::Render { .. } => "render",
Point::Log { .. } => "log",
Point::Note(_) => "note",
}
}
}
impl fmt::Display for Bus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Bus::Global => "global",
Bus::Window => "window",
})
}
}
impl fmt::Display for StoreOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
StoreOp::Set => "set",
StoreOp::Delete => "delete",
StoreOp::DeletePrefix => "delete_prefix",
})
}
}
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Point::Action { message } => write!(f, "action {message}"),
Point::Send { actor, message } => write!(f, "send {message} → {actor}"),
Point::Handle { actor, message } => write!(f, "{actor} handles {message}"),
Point::Spawn { actor, output, .. } => write!(f, "{actor} starts work for {output}"),
Point::Settled {
actor,
output,
took_us,
..
} => write!(
f,
"{actor} has its {output} after {:.1} ms",
*took_us as f64 / 1000.0
),
Point::Cancelled {
actor,
output,
took_us,
..
} => write!(
f,
"{actor} is gone: {output} cancelled after {:.1} ms",
*took_us as f64 / 1000.0
),
Point::Publish {
event,
bus,
subscribers,
} => write!(f, "publish {event} on the {bus} bus to {subscribers}"),
Point::Deliver { event, bus } => write!(f, "deliver {event} from the {bus} bus"),
Point::Push { reducer } => write!(f, "push into {reducer}"),
Point::Navigate { root, to } => write!(f, "{root} navigates to {to}"),
Point::Tick { timer } => write!(f, "timer #{timer}"),
Point::Render { segment, took_us } => {
write!(f, "{segment} drew itself in {:.1} ms", *took_us as f64 / 1000.0)
}
Point::Store {
op,
path,
field,
outside,
} => {
let who = if *outside { "disk" } else { "store" };
let verb = match op {
StoreOp::Set => "sets",
StoreOp::Delete => "deletes",
StoreOp::DeletePrefix => "clears",
};
write!(f, "{who} {verb} {path}")?;
match field {
Some(field) => write!(f, " ({field})"),
None => Ok(()),
}
}
Point::Log {
level,
target,
text,
..
} => write!(f, "{level} {target}: {text}"),
Point::Note(text) => f.write_str(text),
}
}
}