Skip to main content

crap4rust/analysis/
source_function_discovery.rs

1// Copyright 2026 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License
3// SPDX-License-Identifier: MIT
4
5use anyhow::Result;
6
7use crate::analysis::file_walker::FileWalker;
8use crate::analysis::source_function::SourceFunction;
9use crate::invocation::package_context::PackageContext;
10use crate::traits::function_discovery::FunctionDiscovery;
11
12#[derive(Debug, Clone, Copy, Default)]
13pub struct SourceFunctionDiscovery;
14
15impl SourceFunctionDiscovery {
16    #[must_use]
17    pub const fn new() -> Self {
18        Self
19    }
20
21    fn discover_functions(package: &PackageContext) -> Result<Vec<SourceFunction>> {
22        let walker = FileWalker::new(package);
23        let mut functions = Vec::new();
24        for source_root in &package.source_roots {
25            functions.extend(walker.process_source_root(source_root)?);
26        }
27        Ok(functions)
28    }
29}
30
31impl FunctionDiscovery for SourceFunctionDiscovery {
32    fn discover(&self, package: &PackageContext) -> Result<Vec<SourceFunction>> {
33        Self::discover_functions(package)
34    }
35}