Bank

Trait Bank 

Source
pub trait Bank {
    // Required method
    fn generate(&self, config: &BankConfig) -> Result<String>;
}
Expand description

Trait to generate a code bank for a given directory.

This trait is implemented by code bank generators to process source code and generate documentation in a structured format. If the language for a given file is not supported, it will be skipped.

§Examples

use codebank::{Bank, BankConfig, BankStrategy, CodeBank};
use std::path::Path;

// Create a new code bank generator
let code_bank = CodeBank::try_new()?;

// Generate documentation using the Bank trait
let config = BankConfig::new(Path::new("src"), BankStrategy::Default, vec![]);
let content = code_bank.generate(&config)?;

// The generated content should be markdown
assert!(content.starts_with("# Code Bank"));

§Custom Implementation

You can implement this trait for your own code bank generator:

use codebank::{Bank, BankConfig, BankStrategy, Result};
use std::path::Path;

struct MyCodeBank;

impl Bank for MyCodeBank {
    fn generate(&self, config: &BankConfig) -> Result<String> {
        // Your implementation here
        Ok("# Code Bank\n\nCustom implementation".to_string())
    }
}

let my_bank = MyCodeBank;
let config = BankConfig::new(Path::new("."), BankStrategy::Default, vec![]);
let content = my_bank.generate(&config)?;
assert!(content.starts_with("# Code Bank"));

Required Methods§

Source

fn generate(&self, config: &BankConfig) -> Result<String>

Generate a summary for the given directory using the specified strategy.

§Arguments
  • root_dir - The root directory to process
  • strategy - The strategy to use for generation
§Returns

Returns a Result containing the generated documentation as a string, or an error if the generation fails.

§Errors

This function will return an error if:

  • The root directory does not exist
  • The root directory is not actually a directory
  • File reading or parsing fails
§Examples
use codebank::{Bank, BankConfig, BankStrategy, CodeBank};
use std::path::Path;

let code_bank = CodeBank::try_new()?;

// Generate documentation for the src directory
let config = BankConfig::new(Path::new("src"), BankStrategy::Default, vec![]);
let content = code_bank.generate(&config)?;

println!("Generated documentation:\n{}", content);

Implementors§