pub struct GraphBuilderV2<'a> { /* private fields */ }Expand description
Builder for constructing CodeGraphV2.
Provides a convenient API for adding symbols and relationships to the graph.
§Example
let mut registry = SymbolRegistry::new();
let mut builder = GraphBuilderV2::new(&mut registry);
let foo = builder.add_symbol(SymbolPath::parse("mylib::foo")?, SymbolKind::Function)?;
let bar = builder.add_symbol(SymbolPath::parse("mylib::bar")?, SymbolKind::Function)?;
builder.add_call(foo, bar);
let graph = builder.build();Implementations§
Source§impl<'a> GraphBuilderV2<'a>
impl<'a> GraphBuilderV2<'a>
Sourcepub fn new(registry: &'a mut SymbolRegistry) -> Self
pub fn new(registry: &'a mut SymbolRegistry) -> Self
Create a new builder.
Sourcepub fn with_capacity(
registry: &'a mut SymbolRegistry,
nodes: usize,
edges: usize,
) -> Self
pub fn with_capacity( registry: &'a mut SymbolRegistry, nodes: usize, edges: usize, ) -> Self
Create a new builder with pre-allocated capacity.
Sourcepub fn add_symbol(
&mut self,
path: SymbolPath,
kind: SymbolKind,
) -> Result<SymbolId, RegistrationError>
pub fn add_symbol( &mut self, path: SymbolPath, kind: SymbolKind, ) -> Result<SymbolId, RegistrationError>
Add a symbol to both registry and graph.
Returns the SymbolId for the added symbol. Also adds the symbol to the kind index for efficient kind-based queries.
Sourcepub fn add_existing_symbol(&mut self, id: SymbolId, kind: SymbolKind)
pub fn add_existing_symbol(&mut self, id: SymbolId, kind: SymbolKind)
Add an existing symbol to the graph (already registered in registry).
Use this when the symbol is already registered but not yet in the graph.
Sourcepub fn add_crate_root(
&mut self,
path: SymbolPath,
) -> Result<SymbolId, RegistrationError>
pub fn add_crate_root( &mut self, path: SymbolPath, ) -> Result<SymbolId, RegistrationError>
Add a crate root.
Sourcepub fn add_existing_crate_root(&mut self, id: SymbolId)
pub fn add_existing_crate_root(&mut self, id: SymbolId)
Add an existing symbol as a crate root.
Sourcepub fn add_contains(&mut self, parent: SymbolId, child: SymbolId)
pub fn add_contains(&mut self, parent: SymbolId, child: SymbolId)
Add a Contains relationship (parent → child).
Sourcepub fn add_call(&mut self, caller: SymbolId, callee: SymbolId)
pub fn add_call(&mut self, caller: SymbolId, callee: SymbolId)
Add a Calls relationship (caller → callee).
Sourcepub fn add_implements(&mut self, implementor: SymbolId, trait_or_type: SymbolId)
pub fn add_implements(&mut self, implementor: SymbolId, trait_or_type: SymbolId)
Add an Implements relationship (implementor → trait/type).
Sourcepub fn add_match_expr(
&mut self,
function_id: SymbolId,
file_id: FileId,
enum_id: SymbolId,
offset: u32,
line: u32,
)
pub fn add_match_expr( &mut self, function_id: SymbolId, file_id: FileId, enum_id: SymbolId, offset: u32, line: u32, )
Add a match expression to a function (String-free version).
Uses FileId and SymbolId instead of PathBuf and String.
§Arguments
function_id- The function containing the match expressionfile_id- The file containing the match expressionenum_id- The enum being matchedoffset- Byte offset in the fileline- Line number (1-indexed)
Sourcepub fn build(self) -> CodeGraphV2
pub fn build(self) -> CodeGraphV2
Build the graph, consuming the builder.
Note: Unlike V1, indices are built incrementally during add_symbol, so no post-build index rebuild is needed.
Sourcepub fn registry(&self) -> &SymbolRegistry
pub fn registry(&self) -> &SymbolRegistry
Get a reference to the registry.
Sourcepub fn registry_mut(&mut self) -> &mut SymbolRegistry
pub fn registry_mut(&mut self) -> &mut SymbolRegistry
Get a mutable reference to the registry.
Sourcepub fn graph(&self) -> &CodeGraphV2
pub fn graph(&self) -> &CodeGraphV2
Get a reference to the graph being built.
Auto Trait Implementations§
impl<'a> Freeze for GraphBuilderV2<'a>
impl<'a> RefUnwindSafe for GraphBuilderV2<'a>
impl<'a> Send for GraphBuilderV2<'a>
impl<'a> Sync for GraphBuilderV2<'a>
impl<'a> Unpin for GraphBuilderV2<'a>
impl<'a> UnsafeUnpin for GraphBuilderV2<'a>
impl<'a> !UnwindSafe for GraphBuilderV2<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more