use super::FileType;
use log::error;
impl From<&String> for FileType {
fn from(extension: &String) -> FileType {
let extension: &str = extension;
match extension {
"ts" => FileType::TypeScript,
"js" => FileType::JavaScript,
"toml" => FileType::Toml,
"tml" => FileType::Tml,
"json" => FileType::Json,
"hcl" => FileType::Hcl,
"yaml" => FileType::Yaml,
"yml" => FileType::Yml,
_ => {
let message = format!("Couldn't parse file with extension .{}", extension);
let _hint = "Assuming default typescript file";
error!("{}", message);
FileType::TypeScript
}
}
}
}
impl From<&FileType> for String {
fn from(file_type: &FileType) -> String {
match file_type {
FileType::TypeScript => "ts".to_owned(),
FileType::JavaScript => "js".to_owned(),
FileType::Json => "json".to_owned(),
FileType::Toml => "toml".to_owned(),
FileType::Tml => "tml".to_owned(),
FileType::Hcl => "hcl".to_owned(),
FileType::Yaml => "yaml".to_owned(),
FileType::Yml => "yml".to_owned(),
}
}
}