dry4rust/rust/
rust_analyzer.rs1use std::path::Path;
13
14use super::parser::parse_source;
15use crate::analysis_config::AnalysisConfig;
16use crate::analyzer::LanguageAnalyzer;
17use crate::code_unit::CodeUnit;
18use std::error::Error;
19
20pub struct RustAnalyzer;
22
23impl RustAnalyzer {
24 #[must_use]
25 pub const fn new() -> Self {
26 Self
27 }
28}
29
30impl Default for RustAnalyzer {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36impl LanguageAnalyzer for RustAnalyzer {
37 fn is_test_code(&self, unit: &CodeUnit) -> bool {
38 unit.is_test
39 }
40
41 fn file_extensions(&self) -> &[&str] {
42 &["rs"]
43 }
44
45 fn parse_file(
46 &self,
47 path: &Path,
48 source: &str,
49 config: &AnalysisConfig,
50 ) -> Result<Vec<CodeUnit>, Box<dyn Error + Send + Sync>> {
51 parse_source(path, source, config.min_nodes, config.min_lines)
52 .map_err(|e| -> Box<dyn Error + Send + Sync> { e.into() })
53 }
54}