Added documentation

This commit is contained in:
Lucien Cartier-Tilet 2020-03-27 23:27:00 +01:00
parent 7d0a371311
commit 9f5c040893
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -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<SettingsType> {
let extension = match path.extension() {
None => {