use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum EdgeKind {
Calls,
Imports,
Extends,
Implements,
UsesType,
References,
Contains,
FlowsTo,
DataDependency,
}
impl std::fmt::Display for EdgeKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Calls => "calls",
Self::Imports => "imports",
Self::Extends => "extends",
Self::Implements => "implements",
Self::UsesType => "uses_type",
Self::References => "references",
Self::Contains => "contains",
Self::FlowsTo => "flows_to",
Self::DataDependency => "data_dependency",
};
write!(f, "{}", s)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Edge {
pub kind: EdgeKind,
pub file: Option<String>,
pub line: Option<u32>,
}
impl Edge {
pub fn new(kind: EdgeKind) -> Self {
Self {
kind,
file: None,
line: None,
}
}
pub fn with_location(kind: EdgeKind, file: impl Into<String>, line: u32) -> Self {
Self {
kind,
file: Some(file.into()),
line: Some(line),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GraphEdge {
pub source: String,
pub target: String,
pub kind: EdgeKind,
}