2018-10-09 19:34:30 +00:00
|
|
|
pub(crate) trait Counter: salsa::Database {
|
2018-09-29 08:50:08 +00:00
|
|
|
fn increment(&self) -> usize;
|
|
|
|
}
|
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
#[salsa::query_group]
|
|
|
|
pub(crate) trait Database: Counter {
|
|
|
|
fn memoized(&self) -> usize;
|
|
|
|
#[salsa::volatile]
|
|
|
|
fn volatile(&self) -> usize;
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 09:51:18 +00:00
|
|
|
/// Because this query is memoized, we only increment the counter
|
|
|
|
/// the first time it is invoked.
|
2018-10-19 01:26:48 +00:00
|
|
|
fn memoized(db: &impl Database) -> usize {
|
|
|
|
db.volatile()
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 09:51:18 +00:00
|
|
|
/// Because this query is volatile, each time it is invoked,
|
|
|
|
/// we will increment the counter.
|
2018-10-19 01:26:48 +00:00
|
|
|
fn volatile(db: &impl Database) -> usize {
|
2018-10-05 14:30:17 +00:00
|
|
|
db.increment()
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|