diff --git a/src/settings/utils.rs b/src/settings/utils.rs index ece95b5..22129b7 100644 --- a/src/settings/utils.rs +++ b/src/settings/utils.rs @@ -83,6 +83,30 @@ where Ok(()) } +/// Get the type of file to be opened based on its extension. Currently +/// supported file types are: +/// * JSON - `.json` extension +/// * Yaml - `.yml` or `.yaml` extensions +/// +/// # Arguments +/// +/// - `path` - Path of the file to be determined +/// +/// # Example +/// +/// ``` +/// let file_json = std::path::Path::new("file.json"); +/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Json, +/// lang_evolve_core::settings::utils::get_file_type(&file_json).unwrap()); +/// +/// let file_yaml = std::path::Path::new("file.yaml"); +/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Yaml, +/// lang_evolve_core::settings::utils::get_file_type(&file_yaml).unwrap()); +/// +/// let file_yml = std::path::Path::new("file.yml"); +/// assert_eq!(lang_evolve_core::settings::utils::SettingsType::Yaml, +/// lang_evolve_core::settings::utils::get_file_type(&file_yml).unwrap()); +/// ``` pub fn get_file_type(path: &Path) -> Result { let extension = match path.extension() { None => {