Struct ContextGenerator

Source
pub struct ContextGenerator { /* private fields */ }
Expand description

Context generator that creates structured markdown from repository scan results.

The generator takes scan results and creates a prioritized, token-limited markdown document suitable for consumption by LLMs and AI agents. Content is organized by priority, with metadata and documentation receiving higher priority than source code.

§Examples

use ai_context_gen::{Config, ContextGenerator, RepositoryScanner};

let config = Config::default();
let scanner = RepositoryScanner::new(config.clone());
let scan_result = scanner.scan().await?;

let generator = ContextGenerator::new(config);
generator.generate_context(scan_result).await?;

Implementations§

Source§

impl ContextGenerator

Source

pub fn new(config: Config) -> Self

Creates a new context generator with the given configuration.

§Arguments
  • config - Configuration specifying output options and token limits
§Panics

Panics if the content prioritizer cannot be initialized (e.g., if the tiktoken model cannot be loaded).

§Examples
use ai_context_gen::{Config, ContextGenerator};

let config = Config::default();
let generator = ContextGenerator::new(config);
Source

pub async fn generate_context(&self, scan_result: ScanResult) -> Result<()>

Generates a complete context document from scan results.

This method creates a structured markdown document with prioritized content sections including project metadata, file structure, documentation, AST analysis, and source code. Content is prioritized and truncated based on the configured token limit.

§Arguments
  • scan_result - Results from repository scanning containing files and metadata
§Returns

Returns Ok(()) if the context was successfully generated and written to the configured output file.

§Errors

Returns an error if:

  • AST parsing fails for Rust files
  • The output file cannot be written
  • Token counting or content prioritization fails
§Examples
use ai_context_gen::{Config, ContextGenerator, RepositoryScanner};

let config = Config::default();
let scanner = RepositoryScanner::new(config.clone());
let scan_result = scanner.scan().await?;

let generator = ContextGenerator::new(config);
generator.generate_context(scan_result).await?;

println!("Context generated successfully!");

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.