Rust language plugin for CodeGraph. Extracts code entities from Rust source files using tree-sitter-rust.
.rs
| Rust Concept | CodeGraph Entity |
|---|---|
struct |
ClassEntity |
trait |
InterfaceEntity |
fn (top-level) |
FunctionEntity |
impl methods |
FunctionEntity (impl type encoded in ID) |
const |
VariableEntity (kind: const) |
static |
VariableEntity (kind: let) |
use |
ImportEntity |
type alias |
TypeEntity (kind: type) |
enum |
TypeEntity (kind: enum) |
impl Trait for Struct |
InheritanceReference (implements) |
trait X: Y |
InheritanceReference (extends) |
- Functions & Methods -- Parameters with types (including
selfparameter), return types, async detection viafunction_modifiers, doc comments (///), complexity metrics. Methods insideimplblocks have their impl type recorded in the entity ID. - Structs -- Visibility detection (
pub), doc comments. - Traits -- Supertrait bounds extracted as
extendsrelationships (e.g.,trait Handler: Send + Sync). Visibility and doc comments. - Variables --
constandstaticitems with type annotations. - Imports -- All
usedeclaration forms: simple paths (use std::io::Read), grouped (use std::io::{Read, Write}), wildcards (use std::io::*), aliased (use X as Y), and single crate imports. - Types -- Type aliases and enums with visibility and doc comments.
- Calls -- Function and method calls including direct (
helper()), method (self.method()), and qualified (Type::method()). Filters Rust builtins and common trait methods (clone,unwrap,map,into,collect, etc.). - Inheritance --
impl Trait for Typecreates implements edges. Trait supertrait bounds create extends edges.
Checks for visibility_modifier child nodes (pub, pub(crate), etc.).
Uses the @codegraph/plugin-generic factory with custom override extractors for all entity types. The plugin is exported as rustPlugin.
import { rustPlugin } from '@codegraph/plugin-rust';
rustPlugin.extractAllEntities(root, filePath);
// Individual extractors
import {
extractFunctions,
extractClasses,
extractInterfaces,
extractVariables,
extractImports,
extractTypes,
extractCalls,
extractInheritance,
} from '@codegraph/plugin-rust';Uses tree-sitter-rust.