use std::path::PathBuf;
#[allow(dead_code)]
pub fn vet_input_file_path_buf_exists(input: &PathBuf) -> Result<(), impl std::error::Error> {
match input.exists() {
true => Ok(()),
false => Err(Error::InputFileMustExist(input.to_owned()))
}
}
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("InputFileMustExist ➡ input: {0:?}")]
InputFileMustExist(PathBuf),
}
#[cfg(test)]
mod tests {
use super::*;
use once_cell::sync::Lazy;
use std::path::PathBuf;
pub static DIR: Lazy<PathBuf> = Lazy::new(||
crate::testing::TESTS_DIR
.join("src")
.join("f")
.join("vet_input_file_path_buf_exists")
);
#[test]
fn test_vet_input_file_path_buf_exists_x_ok() {
let x = vet_input_file_path_buf_exists(&DIR.join("example.txt"));
x.unwrap();
}
#[test]
fn test_vet_input_file_path_buf_exists_x_err() {
let x = vet_input_file_path_buf_exists(&DIR.join("missing.txt"));
assert!(x.is_err());
}
}