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§
Sourcefn search(
&self,
query: &str,
path: &Path,
options: &SearchOptions,
) -> Result<Vec<SearchResult>, Box<dyn Error>>
fn search( &self, query: &str, path: &Path, options: &SearchOptions, ) -> Result<Vec<SearchResult>, Box<dyn Error>>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".