mirror of
https://github.com/safishamsi/graphify.git
synced 2026-07-13 10:57:13 +00:00
7eb847bcf7
extract_rust() only traversed field_declaration_list (named-struct bodies), so tuple structs -- whose positional fields nest under ordered_field_declaration_list -- had every field type reference silently dropped from the graph. This is the same node shape the enum handler already accounts for (tuple variants nest their types under ordered_field_declaration_list); the struct path was simply left behind. Add an additive branch that, for each type node in a tuple struct's ordered_field_declaration_list, collects type refs via _rust_collect_type_refs and emits references edges with the appropriate field / generic_arg context. The named-struct path is untouched. For `struct Wrapper(Logger, Config);` with Logger/Config defined in-file, no field edges were produced before; both are now emitted. Adds test_rust_tuple_struct_field_references and a tuple struct to the shared Rust fixture covering plain and generic positional field types.
61 lines
1.0 KiB
Rust
61 lines
1.0 KiB
Rust
use std::collections::HashMap;
|
|
|
|
struct Graph {
|
|
nodes: HashMap<String, Vec<String>>,
|
|
}
|
|
|
|
impl Graph {
|
|
fn new() -> Self {
|
|
Graph { nodes: HashMap::new() }
|
|
}
|
|
|
|
fn add_node(&mut self, id: String) {
|
|
self.nodes.insert(id, vec![]);
|
|
}
|
|
|
|
fn add_edge(&mut self, src: String, tgt: String) {
|
|
self.nodes.entry(src).or_default().push(tgt);
|
|
}
|
|
}
|
|
|
|
fn build_graph(edges: Vec<(String, String)>) -> Graph {
|
|
let mut g = Graph::new();
|
|
for (src, tgt) in edges {
|
|
g.add_edge(src, tgt);
|
|
}
|
|
g
|
|
}
|
|
|
|
trait Processor {
|
|
fn run(&self);
|
|
}
|
|
|
|
trait Logger: Processor {
|
|
fn log(&self);
|
|
}
|
|
|
|
struct Result<T> {
|
|
value: T,
|
|
}
|
|
|
|
struct DataProcessor {
|
|
current: Result<DataProcessor>,
|
|
}
|
|
|
|
impl Processor for DataProcessor {
|
|
fn run(&self) {}
|
|
}
|
|
|
|
impl DataProcessor {
|
|
fn build(input: DataProcessor) -> Result<DataProcessor> {
|
|
Result { value: input }
|
|
}
|
|
}
|
|
|
|
enum GraphEvent {
|
|
NodeAdded(Graph),
|
|
Processed { proc: DataProcessor },
|
|
}
|
|
|
|
struct GraphPair(Graph, Result<DataProcessor>);
|