usestd::env;usestd::env::current_dir;usestd::path::PathBuf;usedirs::home_dir;usecrate::utils::TemplatedPathBuf;// Calculates the cache root path once.
pubfnxet_cache_root()-> PathBuf{// if HF_HOME is set use that instead of ~/.cache/huggingface
// if HF_XET_CACHE is set use that instead of ~/.cache/huggingface/xet
// HF_XET_CACHE takes precedence over HF_HOME
// If HF_XET_CACHE is set, use that directly.
ifletOk(cache)=env::var("HF_XET_CACHE"){TemplatedPathBuf::evaluate(cache)// If HF_HOME is set, use the $HF_HOME/xet
}elseifletOk(hf_home)=env::var("HF_HOME"){TemplatedPathBuf::evaluate(hf_home).join("xet")// If XDG_CACHE_HOME is set, use the $XDG_CACHE_HOME/huggingface/xet, otherwise
// use $HOME/.cache/huggingface/xet
}elseifletOk(xdg_cache_home)=env::var("XDG_CACHE_HOME"){TemplatedPathBuf::evaluate(xdg_cache_home).join("huggingface").join("xet")// Use the same default as huggingface_hub, ~/.cache/huggingface/xet (slightly nonstandard, but won't
// mess with it).
}else{home_dir().unwrap_or(current_dir().unwrap_or_else(|_|".".into())).join(".cache").join("huggingface").join("xet")}}