Skip to main content

SearchEngine

Trait SearchEngine 

Source
pub trait SearchEngine: Send + Sync {
    // Required method
    fn search(
        &self,
        query: &str,
        path: &Path,
        options: &SearchOptions,
    ) -> Result<Vec<SearchResult>, Box<dyn Error>>;
}
Expand description

Trait for search engine implementations

This trait allows different search strategies to be implemented and tested independently. It enables dependency injection and makes the code more testable by allowing mock implementations.

§Examples

use codesearch::traits::SearchEngine;
use codesearch::types::{SearchOptions, SearchResult};
use std::path::Path;

struct MockSearchEngine;

impl SearchEngine for MockSearchEngine {
    fn search(&self, query: &str, path: &Path, options: &SearchOptions)
        -> Result<Vec<SearchResult>, Box<dyn std::error::Error>> {
        // Return mock results for testing
        Ok(vec![])
    }
}

Required Methods§

Source

fn search( &self, query: &str, path: &Path, options: &SearchOptions, ) -> Result<Vec<SearchResult>, Box<dyn Error>>

Search for patterns in code files

§Arguments
  • query - The search pattern (regex or literal)
  • path - The directory path to search in
  • options - Search configuration options
§Returns

A vector of search results or an error

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§