pub struct RelevantContext {
pub entry: FunctionContext,
pub callees: Vec<FunctionContext>,
pub callers: Vec<FunctionContext>,
pub token_count: usize,
pub depth: usize,
}Expand description
Relevant context for LLM consumption with call graph information.
This struct aggregates function context for an entry point along with
its direct callees and callers, providing a complete picture for LLM analysis.
Matches Python’s RelevantContext dataclass for API parity.
§Examples
use go_brrr::{RelevantContext, FunctionContext};
// Build context programmatically
let entry = FunctionContext::minimal("main", "src/main.rs", 10, "rust");
let callee = FunctionContext::minimal("helper", "src/utils.rs", 25, "rust");
let context = RelevantContext {
entry,
callees: vec![callee],
callers: vec![],
token_count: 500,
depth: 1,
};
println!("Entry: {} calls {} functions", context.entry.name, context.callees.len());Fields§
§entry: FunctionContextThe entry point function being analyzed
callees: Vec<FunctionContext>Functions called by the entry point (direct dependencies)
callers: Vec<FunctionContext>Functions that call the entry point (reverse dependencies)
token_count: usizeEstimated token count for LLM context window budgeting
depth: usizeDepth of call graph traversal used
Implementations§
Source§impl RelevantContext
impl RelevantContext
Sourcepub fn new(entry: FunctionContext, depth: usize) -> Self
pub fn new(entry: FunctionContext, depth: usize) -> Self
Create a new RelevantContext with just an entry point.
Callees and callers are initialized empty; use builder pattern to add them.
Sourcepub fn with_callee(self, callee: FunctionContext) -> Self
pub fn with_callee(self, callee: FunctionContext) -> Self
Add a callee (function called by entry point).
Sourcepub fn with_caller(self, caller: FunctionContext) -> Self
pub fn with_caller(self, caller: FunctionContext) -> Self
Add a caller (function that calls the entry point).
Sourcepub fn with_token_count(self, count: usize) -> Self
pub fn with_token_count(self, count: usize) -> Self
Set the token count estimate.
Sourcepub fn estimate_tokens(&mut self)
pub fn estimate_tokens(&mut self)
Calculate approximate token count based on source code length.
Uses a rough estimate of 4 characters per token.
Sourcepub fn function_count(&self) -> usize
pub fn function_count(&self) -> usize
Total number of functions in this context.
Sourcepub fn to_llm_string(&self) -> String
pub fn to_llm_string(&self) -> String
Format context as a string suitable for LLM prompts.
Produces a structured representation showing the entry point and its relationships to other functions.
Trait Implementations§
Source§impl Clone for RelevantContext
impl Clone for RelevantContext
Source§fn clone(&self) -> RelevantContext
fn clone(&self) -> RelevantContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RelevantContext
impl Debug for RelevantContext
Source§impl<'de> Deserialize<'de> for RelevantContext
impl<'de> Deserialize<'de> for RelevantContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for RelevantContext
impl RefUnwindSafe for RelevantContext
impl Send for RelevantContext
impl Sync for RelevantContext
impl Unpin for RelevantContext
impl UnwindSafe for RelevantContext
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request