salsa/tests/storage_varieties/queries.rs

28 lines
689 B
Rust
Raw Normal View History

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;
}
salsa::query_prototype! {
2018-10-05 08:54:51 +00:00
crate trait Database: Counter {
2018-09-29 08:50:08 +00:00
fn memoized() for Memoized;
2018-09-30 10:05:42 +00:00
fn volatile() for Volatile;
2018-09-29 08:50:08 +00:00
}
}
salsa::query_definition! {
2018-09-29 08:53:59 +00:00
/// Because this query is memoized, we only increment the counter
/// the first time it is invoked.
2018-10-05 08:54:51 +00:00
crate Memoized(db: &impl Database, (): ()) -> usize {
db.increment()
2018-09-29 08:50:08 +00:00
}
}
salsa::query_definition! {
2018-09-30 10:05:42 +00:00
/// Because this query is volatile, each time it is invoked,
2018-09-29 08:53:59 +00:00
/// we will increment the counter.
2018-09-30 10:05:42 +00:00
#[storage(volatile)]
2018-10-05 08:54:51 +00:00
crate Volatile(db: &impl Database, (): ()) -> usize {
db.increment()
2018-09-29 08:50:08 +00:00
}
}