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;
|
|
|
|
}
|
|
|
|
|
2018-10-05 14:35:50 +00:00
|
|
|
salsa::query_group! {
|
2018-10-09 19:34:30 +00:00
|
|
|
pub(crate) trait Database: Counter {
|
2018-10-19 01:26:48 +00:00
|
|
|
fn memoized() -> usize {
|
2018-10-05 09:28:51 +00:00
|
|
|
type Memoized;
|
|
|
|
}
|
2018-10-19 01:26:48 +00:00
|
|
|
fn volatile() -> usize {
|
2018-10-05 09:28:51 +00:00
|
|
|
type Volatile;
|
2018-10-05 09:51:18 +00:00
|
|
|
storage volatile;
|
2018-10-05 09:28:51 +00:00
|
|
|
}
|
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
|
|
|
}
|