salsa/tests/storage_varieties/queries.rs

23 lines
569 B
Rust
Raw Normal View History

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;
}
#[salsa::query_group(GroupStruct)]
pub(crate) trait Database: Counter {
fn memoized(&self) -> usize;
#[salsa::volatile]
fn volatile(&self) -> usize;
2018-09-29 08:50:08 +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
}
/// 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
}