2018-10-05 08:54:51 +00:00
|
|
|
crate trait Counter: salsa::Database {
|
2018-09-29 08:50:08 +00:00
|
|
|
fn increment(&self) -> usize;
|
|
|
|
}
|
|
|
|
|
2018-10-02 00:42:41 +00:00
|
|
|
salsa::query_prototype! {
|
2018-10-05 08:54:51 +00:00
|
|
|
crate trait Database: Counter {
|
2018-10-05 09:28:51 +00:00
|
|
|
fn memoized(key: ()) -> usize {
|
|
|
|
type Memoized;
|
|
|
|
}
|
|
|
|
fn volatile(key: ()) -> usize {
|
|
|
|
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-05 14:30:17 +00:00
|
|
|
fn memoized(db: &impl Database, (): ()) -> usize {
|
|
|
|
db.increment()
|
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-05 14:30:17 +00:00
|
|
|
fn volatile(db: &impl Database, (): ()) -> usize {
|
|
|
|
db.increment()
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|