Skip to content

Commit

Permalink
feat: scan Rust projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieubes committed Nov 21, 2024
1 parent d892434 commit ba30d99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod file_handler;
mod project;

use project::{node_js::NodeProject, scan_project_deps, Project};
use project::{rust::RustProject, scan_project_deps, Project};

fn main() {
println!(
"Running in {} folder.",
std::env::current_dir().unwrap().display()
);

scan_project_deps(NodeProject::default());
scan_project_deps(RustProject::default());
}
26 changes: 14 additions & 12 deletions src/project/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ pub struct RustPackagesHandler {
}

pub struct RustProject {
deps: HashSet<String>,
deps: Vec<String>,

allowed_extensions: HashSet<String>,
excluded_paths: HashSet<String>,
allowed_extensions: Vec<String>,
excluded_paths: Vec<String>,
}

impl RustProject {
fn new(allowed_extensions: HashSet<String>, excluded_paths: HashSet<String>) -> Self {
fn new(allowed_extensions: Vec<String>, excluded_paths: Vec<String>) -> Self {
Self {
allowed_extensions,
excluded_paths,
deps: HashSet::new(),
deps: Vec::new(),
}
}
}

impl Project for RustProject {
fn default() -> Self {
Self::new(
HashSet::from(["rs".into()]),
Vec::from(["rs".into()]),
// For now, excluding Cargo.toml file is not necessary but if in the future we need to
// include .toml files then we can't miss it.
HashSet::from(["Cargo.toml".into()]),
Vec::from(["Cargo.toml".into()]),
)
}

Expand Down Expand Up @@ -83,13 +83,15 @@ impl Project for RustProject {
}
}

fn get_deps_names(parsed_file: RustPackagesHandler) -> HashSet<String> {
HashSet::from_iter(parsed_file
fn get_deps_names(parsed_file: RustPackagesHandler) -> Vec<String> {
let mut names = Vec::from_iter(parsed_file
.dependencies
.iter()
.map(|(name, _version)| {
name.clone()
}))
}));
names.sort();
names
}

#[cfg(test)]
Expand Down Expand Up @@ -117,7 +119,7 @@ mod project_rust_tests {
.dependencies
.insert("bar".into(), "0.1.0".into());

assert_eq!(get_deps_names(packages_handler), HashSet::from(["bar".into(), "foo".into()]));
assert_eq!(get_deps_names(packages_handler), Vec::from(["bar", "foo"]));
}

#[test]
Expand All @@ -130,6 +132,6 @@ mod project_rust_tests {

assert_eq!(project.parse_deps(file_content), 2);
assert_eq!(project.deps.len(), 2);
assert_eq!(project.deps, HashSet::from(["foo".into(), "bar".into()]));
assert_eq!(project.deps, Vec::from(["bar", "foo"]));
}
}

0 comments on commit ba30d99

Please sign in to comment.