pub struct CacheRoot { /* private fields */ }Expand description
Represents a discovered or explicit cache root directory.
Use CacheRoot::from_discovery() to find the nearest crate root from the
current working directory and anchor caches under .cache, or
CacheRoot::from_root(...) to construct one from an explicit path.
Implementations§
Source§impl CacheRoot
impl CacheRoot
Sourcepub fn from_discovery() -> Result<Self>
pub fn from_discovery() -> Result<Self>
Discover the cache root by searching parent directories for Cargo.toml.
The discovered cache root is always <crate-root-or-cwd>/.cache.
Note: from_discovery only uses the configured CACHE_DIR_NAME (by
default .cache) as the discovered cache directory. It does not
detect or prefer other custom directory names (for example
.cache-v2). To use a non-standard cache root name use
CacheRoot::from_root(...) with an explicit path.
Falls back to the current working directory when no crate root is found.
Sourcepub fn from_root<P: Into<PathBuf>>(root: P) -> Self
pub fn from_root<P: Into<PathBuf>>(root: P) -> Self
Create a CacheRoot from an explicit filesystem path.
Sourcepub fn group<P: AsRef<Path>>(&self, relative_group: P) -> CacheGroup
pub fn group<P: AsRef<Path>>(&self, relative_group: P) -> CacheGroup
Build a CacheGroup for a relative subdirectory under this root.
Sourcepub fn group_path<P: AsRef<Path>>(&self, relative_group: P) -> PathBuf
pub fn group_path<P: AsRef<Path>>(&self, relative_group: P) -> PathBuf
Resolve a relative group path to an absolute PathBuf under this root.
Sourcepub fn ensure_group<P: AsRef<Path>>(&self, relative_group: P) -> Result<PathBuf>
pub fn ensure_group<P: AsRef<Path>>(&self, relative_group: P) -> Result<PathBuf>
Ensure the given group directory exists, creating parents as required.
Sourcepub fn ensure_group_with_policy<P: AsRef<Path>>(
&self,
relative_group: P,
policy: Option<&EvictPolicy>,
) -> Result<PathBuf>
pub fn ensure_group_with_policy<P: AsRef<Path>>( &self, relative_group: P, policy: Option<&EvictPolicy>, ) -> Result<PathBuf>
Ensure the given group exists and optionally apply an eviction policy.
When policy is Some, files will be evaluated and removed according
to the EvictPolicy rules. Passing None performs only directory creation.