cache_dir

Function get_cache_dir

Source
pub fn get_cache_dir() -> Result<PathBuf, NoSuchDirectoryError>
Expand description

获取缓存目录的函数

尝试获取当前平台的缓存目录。如果成功,返回一个包含目录路径的Ok值;如果失败,返回一个Err值,其中包含NoSuchDirectoryError错误。 平台包括: Windows, Linux, MacOS, iOS, WASM等。

§返回值

  • Result<PathBuf, NoSuchDirectoryError>: 成功时返回缓存目录的路径,失败时返回错误信息。

§示例

use cache_dir::get_cache_dir;

match get_cache_dir() {
    Ok(cache_dir) => println!("Cache directory: {:?}", cache_dir),
    Err(e) => eprintln!("Error: {}", e),
}
Examples found in repository?
examples/exam.rs (line 5)
4
5
6
7
fn main() -> Result<(), NoSuchDirectoryError> {
    println!("{}", get_cache_dir()?.display());
    Ok(())
}