rust – Finds a file in current or parent directories

As a Rust beginner, I would like to know how I can improve the following points considering the following function:

  • handling Path and PathBuf type correctly;
  • Performance;
  • Rust writing style in general.

Here is the function, decorated with a complete working example:

use std::env;
use std::path::{Path, PathBuf};

const RUSV_FILENAME: &str = ".rusv.json";

/**
 * Find a rusv file in the current or parent directories of the given directory.
 */
fn find_rusv_file(starting_directory: &Path) -> Option {
    let mut directory = starting_directory;
    let rusv_filename = Path::new(&RUSV_FILENAME);

    loop {
        let filepath: PathBuf = (
            directory,
            rusv_filename
        ).iter().collect();

        if filepath.is_file() {
            return Some(filepath);
        }

        match directory.parent() {
            Some(parent) => directory = parent,
            None => return None,
        }
    }
}

fn main() -> std::io::Result<()> {
    let path = env::current_dir()?;

    match find_rusv_file(&path) {
        Some(filepath) => println!("Rusv file was found: {:?}", filepath),
        None => println!("No rusv file was found."),
    };

    Ok(())
}

My question is Not About:

  • Create a more general function (e.g. by specifying the file name as an argument);
  • Everything related to the main() Function.