INNER CODE UNIT · Rust
get_resource
bminixhofer/nlprule · python/src/lib.rs:23
fn get_resource(lang_code: &str, name: &str) -> PyResult<impl Read> {
let version = env!("CARGO_PKG_VERSION");
let mut cache_path: Option<PathBuf> = None;
// try to find a file at which to cache the data
if let Some(project_dirs) = directories::ProjectDirs::from("", "", "nlprule") {
let cache_dir = project_dirs.cache_dir();
cache_path = Some(
cache_dir.join(version).join(lang_code).join(
name.strip_suffix(".gz")
.expect("resource name must have .gz ending."),
),
);
}
// if the file can be read, the data is already cached
if let Some(path) = &cache_path {