1use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
11#[serde(rename_all = "snake_case")]
12pub enum EdgeKind {
13 Calls,
15
16 Imports,
18
19 Extends,
21
22 Implements,
24
25 UsesType,
27
28 References,
30
31 Contains,
33}
34
35impl std::fmt::Display for EdgeKind {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 let s = match self {
38 Self::Calls => "calls",
39 Self::Imports => "imports",
40 Self::Extends => "extends",
41 Self::Implements => "implements",
42 Self::UsesType => "uses_type",
43 Self::References => "references",
44 Self::Contains => "contains",
45 };
46 write!(f, "{}", s)
47 }
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct Edge {
53 pub kind: EdgeKind,
55
56 pub file: Option<String>,
58
59 pub line: Option<u32>,
61}
62
63impl Edge {
64 pub fn new(kind: EdgeKind) -> Self {
66 Self {
67 kind,
68 file: None,
69 line: None,
70 }
71 }
72
73 pub fn with_location(kind: EdgeKind, file: impl Into<String>, line: u32) -> Self {
75 Self {
76 kind,
77 file: Some(file.into()),
78 line: Some(line),
79 }
80 }
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct GraphEdge {
86 pub source: String,
87 pub target: String,
88 pub kind: EdgeKind,
89}