pub struct FunctionContext {
pub name: String,
pub file: String,
pub start_line: usize,
pub end_line: usize,
pub signature: Option<String>,
pub docstring: Option<String>,
pub source: String,
pub language: String,
}Expand description
Context about a function including its code and metadata.
This struct provides a complete context for a single function, suitable for
LLM consumption. It matches Python’s FunctionContext dataclass for API parity.
§Examples
use go_brrr::{FunctionContext, extract_file};
// Create from extracted function info
let module = extract_file("./src/main.py", None)?;
if let Some(func) = module.functions.first() {
let source = std::fs::read_to_string("./src/main.py")?;
let ctx = FunctionContext::from_function_info(func, "./src/main.py", &source, "python");
println!("Function: {} at lines {}-{}", ctx.name, ctx.start_line, ctx.end_line);
}Fields§
§name: StringFunction name
file: StringFile path containing the function
start_line: usizeStart line number (1-indexed)
end_line: usizeEnd line number (1-indexed)
signature: Option<String>Function signature (e.g., “def foo(x: int) -> str”)
docstring: Option<String>Docstring or documentation comment
source: StringFull source code of the function
language: StringProgramming language (e.g., “python”, “rust”, “go”)
Implementations§
Source§impl FunctionContext
impl FunctionContext
Sourcepub fn from_function_info(
info: &FunctionInfo,
file_path: &str,
source: &str,
language: &str,
) -> Self
pub fn from_function_info( info: &FunctionInfo, file_path: &str, source: &str, language: &str, ) -> Self
Create a FunctionContext from a FunctionInfo and source file content.
Extracts the function source code from the full file content using
the line number information in FunctionInfo.
§Arguments
info- The function info from AST extractionfile_path- Path to the source filesource- Full source content of the filelanguage- Programming language identifier
§Examples
use go_brrr::{FunctionContext, extract_file, FunctionInfo};
let module = extract_file("./src/lib.rs", None)?;
let source = std::fs::read_to_string("./src/lib.rs")?;
for func in &module.functions {
let ctx = FunctionContext::from_function_info(func, "./src/lib.rs", &source, "rust");
println!("{}: {} lines", ctx.name, ctx.end_line - ctx.start_line + 1);
}Trait Implementations§
Source§impl Clone for FunctionContext
impl Clone for FunctionContext
Source§fn clone(&self) -> FunctionContext
fn clone(&self) -> FunctionContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FunctionContext
impl Debug for FunctionContext
Source§impl<'de> Deserialize<'de> for FunctionContext
impl<'de> Deserialize<'de> for FunctionContext
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for FunctionContext
impl RefUnwindSafe for FunctionContext
impl Send for FunctionContext
impl Sync for FunctionContext
impl Unpin for FunctionContext
impl UnwindSafe for FunctionContext
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
Wrap the input message
T in a tonic::Request