fn find_record(number: i32, config_record_path: &PathBuf) -> Result<PathBuf, Error> {
    // Define the error message we will return if we can't find the file matching the defined structure.
    let err_not_found = Error::new(ErrorKind::NotFound, "Required file was not found");

    // Create a regex, starting by looking for the exact start of the file, an up-to 4-zero-padded string ending with the variable `number`.
    // e.g. 0001, 0099, 0101, 1234
    let mut str_find_file: String = format!("{:0>4}", number);
    // Add the rest of the regex, looking for anything which is not a back-or-forward slash following a hyphen.
    str_find_file.push_str(r"-[^\\/]*");
    // Then create the regex, using this pattern we've just created.
    let re_find_file = Regex::new(&str_find_file).unwrap();
    // Step through the directory
    let paths = read_dir(config_record_path)?;
    for path in paths {
        // Convert the path into a string we can match with the regex.
        let str_path = path.unwrap().path().display().to_string();
        if re_find_file.is_match(&str_path) {
            // If it matched, turn the string back into a PathBuf and return it.
            return Ok(PathBuf::from(str_path));
        }
    }
    // Otherwise return the error we defined at the start of this function.
    return Err(err_not_found);
}
// Find the file which starts with the 4 character, zero padded string held in number in this directory.
Find the file which starts with the 4 character, zero padded string held in number in this directory.
Find the file which starts with the 4 character zero padded string held in number in this directory .
fn find_record(number: i32, config_record_path: &PathBuf) -> Result<PathBuf, Error> {
    // Define the error message we will return if we can't find the file matching the defined structure.
    let err_not_found = Error::new(ErrorKind::NotFound, "Required file was not found");
    // Create a regex, starting by looking for the exact start of the file, an up-to 4-zero-padded string ending with the variable `number`.
    // e.g. 0001, 0099, 0101, 1234
    let mut str_find_file: String = format!("{:0>4}", number);
    // Add the rest of the regex, looking for anything which is not a back-or-forward slash following a hyphen.
    str_find_file.push_str(r"-[^\\/]*");
    // Then create the regex, using this pattern we've just created.
    let re_find_file = Regex::new(&str_find_file).unwrap();
    // Step through the directory
    let paths = read_dir(config_record_path)?;
    for path in paths {
        // Convert the path into a string we can match with the regex.
        let str_path = path.unwrap().path().display().to_string();
        if re_find_file.is_match(&str_path) {
            // If it matched, turn the string back into a PathBuf and return it.
            return Ok(PathBuf::from(str_path));
        }
    }
    // Otherwise return the error we defined at the start of this function.
    return Err(err_not_found);
}
fn find_record ( number : i32 , config_record_path : & PathBuf ) -> Result < PathBuf , Error > { // Define the error message we will return if we can't find the file matching the defined structure. let err_not_found = Error :: new ( ErrorKind :: NotFound , " " ) ; // Create a regex, starting by looking for the exact start of the file, an up-to 4-zero-padded string ending with the variable `number`. // e.g. 0001, 0099, 0101, 1234 let mut str_find_file : String = format ! ( " " number ) ; // Add the rest of the regex, looking for anything which is not a back-or-forward slash following a hyphen. str_find_file . push_str ( r"-[^\\/]*" ) ; // Then create the regex, using this pattern we've just created. let re_find_file = Regex :: new ( & str_find_file ) . unwrap ( ) ; // Step through the directory let paths = read_dir ( config_record_path ) ? ; for path in paths { // Convert the path into a string we can match with the regex. let str_path = path . unwrap ( ) . path ( ) . display ( ) . to_string ( ) ; if re_find_file . is_match ( & str_path ) { // If it matched, turn the string back into a PathBuf and return it. return Ok ( PathBuf :: from ( str_path ) ) ; } } // Otherwise return the error we defined at the start of this function. return Err ( err_not_found ) ; }
Find the file which starts with the 4 character, zero padded string held in number in this directory.
Find the file which starts with the 4 character zero padded string held in number in this directory .
number
i32
config_record_path
&PathBuf
number
i32
config_record_path
&PathBuf