mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-02 17:52:19 +00:00
c93868c9dc
This ensures consistency of results.
27 lines
669 B
Rust
27 lines
669 B
Rust
crate trait Counter: salsa::Database {
|
|
fn increment(&self) -> usize;
|
|
}
|
|
|
|
salsa::query_group! {
|
|
crate trait Database: Counter {
|
|
fn memoized(key: ()) -> usize {
|
|
type Memoized;
|
|
}
|
|
fn volatile(key: ()) -> usize {
|
|
type Volatile;
|
|
storage volatile;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Because this query is memoized, we only increment the counter
|
|
/// the first time it is invoked.
|
|
fn memoized(db: &impl Database, (): ()) -> usize {
|
|
db.volatile(())
|
|
}
|
|
|
|
/// Because this query is volatile, each time it is invoked,
|
|
/// we will increment the counter.
|
|
fn volatile(db: &impl Database, (): ()) -> usize {
|
|
db.increment()
|
|
}
|