feat(notgraph): define all shared types

This commit is contained in:
Joseph O'Brien
2026-04-02 02:25:16 -04:00
parent f9bd96530e
commit 00b4974e75
2 changed files with 171 additions and 5 deletions

77
Cargo.lock generated
View File

@@ -156,6 +156,38 @@ version = "3.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
[[package]]
name = "camino"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48"
dependencies = [
"serde_core",
]
[[package]]
name = "cargo-platform"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea"
dependencies = [
"serde",
]
[[package]]
name = "cargo_metadata"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037"
dependencies = [
"camino",
"cargo-platform",
"semver",
"serde",
"serde_json",
"thiserror 1.0.69",
]
[[package]]
name = "cc"
version = "1.2.58"
@@ -741,7 +773,7 @@ dependencies = [
"anyhow",
"dirs",
"serde",
"thiserror",
"thiserror 2.0.18",
"toml",
]
@@ -761,6 +793,19 @@ dependencies = [
"toml",
]
[[package]]
name = "notgraph"
version = "0.1.0"
dependencies = [
"anyhow",
"cargo_metadata",
"clap",
"serde",
"serde_json",
"syn",
"walkdir",
]
[[package]]
name = "nothooks"
version = "0.1.0"
@@ -793,7 +838,7 @@ dependencies = [
"scrypt",
"sha2",
"tempfile",
"thiserror",
"thiserror 2.0.18",
"x25519-dalek",
"zeroize",
]
@@ -1053,7 +1098,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
dependencies = [
"getrandom 0.2.17",
"libredox",
"thiserror",
"thiserror 2.0.18",
]
[[package]]
@@ -1178,6 +1223,10 @@ name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
dependencies = [
"serde",
"serde_core",
]
[[package]]
name = "serde"
@@ -1322,13 +1371,33 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"
[[package]]
name = "thiserror"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
dependencies = [
"thiserror-impl",
"thiserror-impl 2.0.18",
]
[[package]]
name = "thiserror-impl"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]

View File

@@ -1 +1,98 @@
// types defined in Task 2
use serde::{Deserialize, Serialize};
pub type CrateName = String;
pub type ModPath = String;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CrateGraph {
pub nodes: Vec<CrateName>,
pub edges: Vec<(CrateName, CrateName)>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModuleGraph {
pub krate: CrateName,
pub nodes: Vec<ModPath>,
pub edges: Vec<(ModPath, ModPath)>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Symbol {
pub mod_path: ModPath,
pub kind: SymbolKind,
pub name: String,
pub is_pub: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum SymbolKind {
Struct,
Enum,
Trait,
Fn,
Type,
Const,
}
impl std::fmt::Display for SymbolKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SymbolKind::Struct => write!(f, "struct"),
SymbolKind::Enum => write!(f, "enum"),
SymbolKind::Trait => write!(f, "trait"),
SymbolKind::Fn => write!(f, "fn"),
SymbolKind::Type => write!(f, "type"),
SymbolKind::Const => write!(f, "const"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SymbolTable {
pub krate: CrateName,
pub symbols: Vec<Symbol>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FanStats {
pub name: String,
pub fan_in: usize,
pub fan_out: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModStats {
pub krate: CrateName,
pub nodes: Vec<FanStats>,
pub cycles: Vec<Vec<ModPath>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum HotspotKind {
FanIn,
FanOut,
}
impl std::fmt::Display for HotspotKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
HotspotKind::FanIn => write!(f, "fan-in"),
HotspotKind::FanOut => write!(f, "fan-out"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Hotspot {
pub name: String,
pub kind: HotspotKind,
pub score: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GraphStats {
pub crate_graph: Vec<FanStats>,
pub module_graphs: Vec<ModStats>,
pub hotspots: Vec<Hotspot>,
pub cycles: Vec<Vec<ModPath>>,
}