Skip to main content

CacheReader

Struct CacheReader 

Source
pub struct CacheReader<Fs: Filesystem> { /* private fields */ }
Expand description

Read-only handle to the cache tree rooted at <workspace_root>/.haz/cache, parameterised over a Filesystem backend.

Pairs with crate::CacheWriter: a writer wraps a reader and adds the mutating operations under the stricter haz_vfs::WritableFilesystem bound. Consumers that only need to consult the cache (e.g. haz cache info per AUX-018, the cache-introspection step of haz why per AUX-014) take a CacheReader and gain a compile-time guarantee that no write can sneak in.

Implementations§

Source§

impl<Fs: Filesystem> CacheReader<Fs>

Source

pub fn info(&self) -> Result<CacheInfoReport, CacheInfoError>

Walk the cache root and classify every entry per AUX-019.

Idempotent on an absent cache root: when <workspace_root>/.haz/cache does not exist, returns the default-zero report rather than an error.

§Errors

Returns CacheInfoError::Io wrapping the underlying FsError when any filesystem read fails. Manifest parse failures and schema mismatches are NOT errors: those entries fold into the CacheInfoReport::corrupt_entries count.

Source§

impl<Fs: Filesystem> CacheReader<Fs>

Source

pub fn lookup(&self, key: &CacheKey) -> Option<Manifest>

Look up the cache entry for key.

Returns Some(Manifest) on a hit (every consistency check from CACHE-016 passed), or None on any miss. Miss reasons enumerated by CACHE-016:

  1. manifest file absent or unreadable;
  2. manifest JSON malformed, contains unknown fields, or uses an unknown hash_function value;
  3. manifest’s chapter_revision does not match crate::CHAPTER_REVISION;
  4. manifest’s hash_function does not match the cache’s active haz_domain::settings::cache::HashAlgo;
  5. any output blob the manifest references is missing, not a regular file, or has a size different from the manifest’s recorded size;
  6. the captured stdout or stderr stream is missing, not a regular file, or has a size different from the manifest’s recorded stdout_len / stderr_len.
Source

pub fn lookup_status( &self, key: &CacheKey, ) -> Result<CacheLookupStatus, CacheLookupError>

Introspecting variant of Self::lookup for AUX-015 step 11.

Performs the same per-entry checks as Self::lookup but discriminates the outcome into the four spec-named sub-states. Reuses the same blob / stream verification (CACHE-015 step 4 / 5), so a hit here is observationally equivalent to a hit from Self::lookup.

§Errors

Returns CacheLookupError::Io wrapping the underlying FsError for filesystem errors that are NOT a “missing entry” shape (those collapse into the CacheLookupStatus::MissNoEntry / CacheLookupStatus::MissCorruptEntry variants).

Source§

impl<Fs: Filesystem> CacheReader<Fs>

Source

pub fn new(fs: Fs, workspace_root: &Path, hash_algo: HashAlgo) -> Self

Construct a CacheReader handle for the workspace rooted at workspace_root. The cache root is derived as <workspace_root>/.haz/cache via layout::cache_root.

hash_algo is the active hash function for this cache session and is used by lookup to reject entries that were written under a different algorithm (CACHE-016 step 3).

Source

pub fn workspace_root(&self) -> &Path

The absolute path to the workspace root. Restoration (CACHE-019) needs this to map workspace-anchored /foo/bar paths recorded in the manifest into real filesystem paths.

Source

pub fn cache_root(&self) -> &Path

The absolute path to the cache root, <workspace_root>/.haz/cache.

Source

pub fn hash_algo(&self) -> HashAlgo

The hash function this CacheReader was constructed with.

Source

pub fn fs(&self) -> &Fs

Borrow the underlying filesystem handle.

Trait Implementations§

Source§

impl<Fs: Clone + Filesystem> Clone for CacheReader<Fs>

Source§

fn clone(&self) -> CacheReader<Fs>

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<Fs: Debug + Filesystem> Debug for CacheReader<Fs>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Fs> Freeze for CacheReader<Fs>
where Fs: Freeze,

§

impl<Fs> RefUnwindSafe for CacheReader<Fs>
where Fs: RefUnwindSafe,

§

impl<Fs> Send for CacheReader<Fs>
where Fs: Send,

§

impl<Fs> Sync for CacheReader<Fs>
where Fs: Sync,

§

impl<Fs> Unpin for CacheReader<Fs>
where Fs: Unpin,

§

impl<Fs> UnsafeUnpin for CacheReader<Fs>
where Fs: UnsafeUnpin,

§

impl<Fs> UnwindSafe for CacheReader<Fs>
where Fs: 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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V