QueryCache in rustc_middle::query::caches - Rust
Description: Trait for types that serve as an in-memory cache for query results, for a given key (argument) type and value (return) type.

Skip to main content

## QueryCache

# Trait QueryCache

Source

    pub trait QueryCache: Sized {
        type Key: QueryKey;
        type Value: Copy;

        // Required methods
        fn lookup(&self, key: &Self::Key) -> Option<(Self::Value, DepNodeIndex)>;
        fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex);
        fn for_each(
            &self,
            f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex),
        );
        fn len(&self) -> usize;
    }

Expand description

Trait for types that serve as an in-memory cache for query results, for a given key (argument) type and value (return) type.

Types implementing this trait are associated with actual key/value types by the `Cache` associated type of the `rustc_middle::query::Key` trait.

## Required Associated Types§

Source

#### type Key: QueryKey

Source

#### type Value: Copy

## Required Methods§

Source

#### fn lookup(&self, key: &Self::Key) -> Option<(Self::Value, DepNodeIndex)>

Returns the cached value (and other information) associated with the given key, if it is present in the cache.

Source

#### fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex)

Adds a key/value entry to this cache.

Called by some part of the query system, after having obtained the value by executing the query or loading a cached value from disk.

Source

#### fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex))

Calls a closure on each entry in this cache.

Source

#### fn len(&self) -> usize

Returns the number of entries currently in this cache.

Useful for reserving capacity in data structures that will hold the output of a call to `Self::for_each`.

## Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementors§

Source§

### impl<K, V> QueryCache for DefaultCache<K, V>
where K: QueryKey, V: Copy,

Source§

#### type Key = K

Source§

#### type Value = V

Source§

### impl<K, V> QueryCache for VecCache<K, V, DepNodeIndex>
where K: Idx + QueryKey, V: Copy,

Source§

#### type Key = K

Source§

#### type Value = V

Source§

### impl<V> QueryCache for DefIdCache<V>
where V: Copy,

Source§

#### type Key = DefId

Source§

#### type Value = V

Source§

### impl<V> QueryCache for SingleCache<V>
where V: Copy,

Source§

#### type Key = ()

Source§

#### type Value = V