cachedir(DEPRECATED), please use dirs instead: https://crates.io/crates/dirs
Replicating the example below, in dirs
:
let cache_dir = dirs::cache_dir().ok_or(
std::io::Error::new(std::io::ErrorKind::Other, "This OS is not supported")
)?.join("CacheName");
std::fs::create_dir_all(&cache_dir).map_err(|err| {
eprintln!("Failed to create cache dir \"{}\": {}", cache_dir.display(), err);
err
})?;
Status: finished
A Rust library that helps with cache directories creation in a system-agnostic way.
Note: even though the crate is at version 0.1
, it should be stable
and its API is not expected to change soon.
Dual-licensed under MIT or the UNLICENSE.
Add this to your Cargo.toml
:
[dependencies]
cachedir = "0.1"
extern crate cachedir;
use cachedir::CacheDirConfig;
fn main() {
let cache_dir = CacheDirConfig::new("CacheName")
.get_cache_dir()
.unwrap();
println!("{}", cache_dir.display());
}
This creates CacheName
into the user's cache directory.
For more information on the types of caches and code examples, please check the documentation.