Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for discovering <dir>/mod.rs mods #16

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,30 @@ fn source_file_names<P: AsRef<Path>>(dir: P) -> Result<Vec<String>> {

for entry in fs::read_dir(dir)? {
let entry = entry?;
if !entry.file_type()?.is_file() {
continue;
}

let file_name = entry.file_name();
if file_name == "mod.rs" || file_name == "lib.rs" || file_name == "main.rs" {
continue;
}

let path = Path::new(&file_name);
if path.extension() == Some(OsStr::new("rs")) {
match file_name.into_string() {
Ok(mut utf8) => {
let path = entry.path();
let file_type = entry.file_type()?;

let is_file_mod = file_type.is_file() && path.extension() == Some(OsStr::new("rs"));
let is_dir_mod = file_type.is_dir() && path.join("mod.rs").exists();
if !(is_file_mod || is_dir_mod) {
continue;
}

match file_name.into_string() {
Ok(mut utf8) => {
if is_file_mod {
utf8.truncate(utf8.len() - ".rs".len());
names.push(utf8);
}
Err(non_utf8) => {
failures.push(non_utf8);
}
names.push(utf8);
}
Err(non_utf8) => {
failures.push(non_utf8);
}
}
}
Expand Down