use lazy_static::lazy_static; use std::ffi::OsStr; use std::path::Path; use std::collections::HashMap; mod txt; fn empty_extractor(_ : &str) -> String { "".to_string() } macro_rules! ext { ($f:ident) => {(stringify!($f), $f::get_text as ExtFn)} } type ExtFn = fn(&str) -> String; lazy_static! { static ref EXT: HashMap<&'static str, ExtFn> = { HashMap::from([ ext!(txt), ]) }; } pub fn extract_text(path : &str) -> String { let p = Path::new(&path); let extenstion = p.extension().unwrap_or_else(|| OsStr::new("")).to_str().unwrap(); EXT.get(extenstion).unwrap_or(&(empty_extractor as ExtFn))(path) }