pub struct CacheResolver {
pub explicit: Option<PathBuf>,
pub env_var: Option<String>,
pub allow_project_discovery: bool,
pub allow_cwd_fallback: bool,
}Expand description
Combined cache-root resolution with a fixed, documented precedence and no
silent <cwd>/.cache scattering.
Precedence (first hit wins, the rest are never consulted):
CacheResolver::explicit— an explicit path (CLI--dir).CacheResolver::env_var— a non-empty env var value.- Cargo workspace discovery (
<workspace>/.cache), unlessCacheResolver::allow_project_discoveryis false. - OS user cache dir for the
project_dirsidentity (requires theos-cache-dirfeature; without it this arm is compiled out).
When nothing matches, resolve() returns Err (kind NotFound) naming
the env var and OS identity that would fix it — it NEVER silently falls
back to <cwd>/.cache. Opt into that legacy behavior per call site with
CacheResolver::allow_cwd_fallback (default false).
Recommended convention: binaries announce the winner on stderr at startup,
e.g. tracing::info!("cache: {} ({:?})", root.path().display(), source).
Zero breaking change: CacheRoot::from_discovery keeps its exact
current semantics (including the CWD fallback) for existing users.
Fields§
§explicit: Option<PathBuf>Explicit path; wins over everything. Usually a CLI --dir flag.
env_var: Option<String>Env var name consulted next (e.g. "WINDOWS_HEADLESS_QEMU_DIR").
Only non-empty values count; unset-or-empty falls through.
allow_project_discovery: boolConsult Cargo workspace discovery. Default true.
allow_cwd_fallback: boolDANGEROUS, default false: allow <cwd>/.cache as a last resort
(the CacheSource::CwdFallback source). Enabling this is a
conscious, greppable opt-in — each shell CWD grows its own cache.
Implementations§
Source§impl CacheResolver
impl CacheResolver
Sourcepub fn resolve(&self) -> Result<(CacheRoot, CacheSource)>
pub fn resolve(&self) -> Result<(CacheRoot, CacheSource)>
Resolve to (root, source) following the documented precedence.