Skip to main content

reposcry_graph/
edge.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
4pub enum EdgeKind {
5    Contains,
6    Imports,
7    Exports,
8    Calls,
9    References,
10    Implements,
11    Extends,
12    UsesType,
13    ReadsConfig,
14    WritesDatabase,
15    ReadsDatabase,
16    EmitsEvent,
17    ConsumesEvent,
18    Tests,
19    DependsOn,
20    ChangedWith,
21    OwnedBy,
22}
23
24impl EdgeKind {
25    pub fn as_str(&self) -> &'static str {
26        match self {
27            EdgeKind::Contains => "contains",
28            EdgeKind::Imports => "imports",
29            EdgeKind::Exports => "exports",
30            EdgeKind::Calls => "calls",
31            EdgeKind::References => "references",
32            EdgeKind::Implements => "implements",
33            EdgeKind::Extends => "extends",
34            EdgeKind::UsesType => "uses_type",
35            EdgeKind::ReadsConfig => "reads_config",
36            EdgeKind::WritesDatabase => "writes_database",
37            EdgeKind::ReadsDatabase => "reads_database",
38            EdgeKind::EmitsEvent => "emits_event",
39            EdgeKind::ConsumesEvent => "consumes_event",
40            EdgeKind::Tests => "tests",
41            EdgeKind::DependsOn => "depends_on",
42            EdgeKind::ChangedWith => "changed_with",
43            EdgeKind::OwnedBy => "owned_by",
44        }
45    }
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct GraphEdge {
50    pub source_id: u64,
51    pub target_id: u64,
52    pub kind: EdgeKind,
53    pub weight: f64,
54    pub metadata: Option<String>,
55}
56
57impl GraphEdge {
58    pub fn new(source_id: u64, target_id: u64, kind: EdgeKind) -> Self {
59        Self {
60            source_id,
61            target_id,
62            kind,
63            weight: 1.0,
64            metadata: None,
65        }
66    }
67}