Skip to main content

CacheResolver

Struct CacheResolver 

Source
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):

  1. CacheResolver::explicit — an explicit path (CLI --dir).
  2. CacheResolver::env_var — a non-empty env var value.
  3. Cargo workspace discovery (<workspace>/.cache), unless CacheResolver::allow_project_discovery is false.
  4. OS user cache dir for the project_dirs identity (requires the os-cache-dir feature; 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: bool

Consult Cargo workspace discovery. Default true.

§allow_cwd_fallback: bool

DANGEROUS, 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

Source

pub fn resolve(&self) -> Result<(CacheRoot, CacheSource)>

Resolve to (root, source) following the documented precedence.

Trait Implementations§

Source§

impl Clone for CacheResolver

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CacheResolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CacheResolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for CacheResolver

§

impl Freeze for CacheResolver
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for CacheResolver

§

impl RefUnwindSafe for CacheResolver

§

impl Send for CacheResolver
where RawVecInner: Send,

§

impl Sync for CacheResolver
where RawVecInner: Sync,

§

impl Unpin for CacheResolver
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for CacheResolver

§

impl UnwindSafe for CacheResolver
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.