moire_types/objects/edges.rs
1use facet::Facet;
2use moire_trace_types::BacktraceId;
3
4use crate::EntityId;
5
6// r[impl model.edge.fields]
7/// Relationship between two entities.
8#[derive(Facet)]
9pub struct Edge {
10 /// Source entity in the causal relationship.
11 pub src: EntityId,
12
13 /// Destination entity in the causal relationship.
14 pub dst: EntityId,
15
16 /// Backtrace when this edge was created
17 pub backtrace: BacktraceId,
18
19 /// Causal edge kind.
20 pub kind: EdgeKind,
21}
22
23impl Edge {
24 /// Builds a causal edge.
25 pub fn new(src: EntityId, dst: EntityId, kind: EdgeKind, backtrace: BacktraceId) -> Self {
26 Self {
27 src,
28 dst,
29 backtrace,
30 kind,
31 }
32 }
33}
34
35// r[impl model.edge.kinds]
36#[derive(Facet, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
37#[repr(u8)]
38#[facet(rename_all = "snake_case")]
39pub enum EdgeKind {
40 /// Poll relationship (task/entity is actively polling another future/resource).
41 ///
42 /// Example: parent future polls child future during one executor tick.
43 Polls,
44
45 /// Waiting relationship (task/entity is blocked on another resource).
46 ///
47 /// Example: receiver waits on channel `rx.recv().await`.
48 WaitingOn,
49
50 /// Pairing relationship between two endpoints that form one logical primitive.
51 ///
52 /// Example: channel sender paired with its corresponding receiver.
53 PairedWith,
54
55 /// Resource ownership/lease relationship (resource -> current holder).
56 ///
57 /// Example: semaphore is held_by the holder of an acquired permit.
58 HeldBy,
59}
60
61crate::impl_sqlite_json!(EdgeKind);
62
63crate::declare_edge_kind_slots!(
64 PollsEdgeKindSlot::Polls,
65 WaitingOnEdgeKindSlot::WaitingOn,
66 PairedWithEdgeKindSlot::PairedWith,
67 HeldByEdgeKindSlot::HeldBy,
68);