rust_rest_test 0.1.1

An executable that can be used to run "unit tests" on a rust api
use std::fs;
use std::fs::{DirEntry, ReadDir};

enum FileType {
    Rrt,
    Dir,
    Ignore,
}

fn is_rrt_file(filename: String) -> bool {
    filename.ends_with(".rrt")
}

fn direntry_is_rrt_file(d: &DirEntry) -> bool {
    d.file_type().unwrap().is_file() && is_rrt_file(d.file_name().to_str().unwrap().to_string())
}

fn tag_entry(entry: DirEntry) -> (FileType, String) {
    if entry.file_type().unwrap().is_dir() {
        (FileType::Dir, dir_to_string(entry))
    } else if direntry_is_rrt_file(&entry) {
        (FileType::Rrt, dir_to_string(entry))
    } else {
        (FileType::Ignore, dir_to_string(entry))
    }
}

fn dir_to_string(entry: DirEntry) -> String {
    format!("{}", entry.path().display())
}

fn organize_entries(entry: ReadDir) -> Vec<(FileType, String)> {
    entry.map(|e| tag_entry(e.unwrap())).collect()
}

fn recursive_rrt_file_list(dir: ReadDir) -> Vec<String> {
    let mut ret: Vec<String> = vec![];
    let files = organize_entries(dir);

    for path in files {
        match path.0 {
            FileType::Dir => ret.extend(all_rrt_files_in_dir(path.1)),
            FileType::Rrt => ret.push(path.1),
            FileType::Ignore => (),
        }
    }

    ret
}

pub fn all_rrt_files_in_dir(dir_location: String) -> Vec<String> {
    let paths = fs::read_dir(dir_location.as_str()).unwrap();
    recursive_rrt_file_list(paths)
}