ra_salsa/
debug.rs

1//! Debugging APIs: these are meant for use when unit-testing or
2//! debugging your application but aren't ordinarily needed.
3
4use crate::durability::Durability;
5use crate::plumbing::QueryStorageOps;
6use crate::Query;
7use crate::QueryTable;
8
9/// Additional methods on queries that can be used to "peek into"
10/// their current state. These methods are meant for debugging and
11/// observing the effects of garbage collection etc.
12pub trait DebugQueryTable {
13    /// Key of this query.
14    type Key;
15
16    /// Value of this query.
17    type Value;
18
19    /// Returns a lower bound on the durability for the given key.
20    /// This is typically the minimum durability of all values that
21    /// the query accessed, but we may return a lower durability in
22    /// some cases.
23    fn durability(&self, key: Self::Key) -> Durability;
24
25    /// Get the (current) set of the entries in the query table.
26    fn entries<C>(&self) -> C
27    where
28        C: FromIterator<TableEntry<Self::Key, Self::Value>>;
29}
30
31/// An entry from a query table, for debugging and inspecting the table state.
32#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
33#[non_exhaustive]
34pub struct TableEntry<K, V> {
35    /// key of the query
36    pub key: K,
37    /// value of the query, if it is stored
38    pub value: Option<V>,
39}
40
41impl<K, V> TableEntry<K, V> {
42    pub(crate) fn new(key: K, value: Option<V>) -> TableEntry<K, V> {
43        TableEntry { key, value }
44    }
45}
46
47impl<Q> DebugQueryTable for QueryTable<'_, Q>
48where
49    Q: Query,
50    Q::Storage: QueryStorageOps<Q>,
51{
52    type Key = Q::Key;
53    type Value = Q::Value;
54
55    fn durability(&self, key: Q::Key) -> Durability {
56        self.storage.durability(self.db, &key)
57    }
58
59    fn entries<C>(&self) -> C
60    where
61        C: FromIterator<TableEntry<Self::Key, Self::Value>>,
62    {
63        self.storage.entries(self.db)
64    }
65}