mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 05:07:27 +00:00
2e40e9d1e5
And use it like `salsa::QueryContext` elsewhere.
27 lines
746 B
Rust
27 lines
746 B
Rust
crate trait CounterContext: salsa::QueryContext {
|
|
fn increment(&self) -> usize;
|
|
}
|
|
|
|
crate trait QueryContext: CounterContext {
|
|
salsa::query_prototype! {
|
|
fn memoized() for Memoized;
|
|
fn transparent() for Transparent;
|
|
}
|
|
}
|
|
|
|
salsa::query_definition! {
|
|
/// Because this query is memoized, we only increment the counter
|
|
/// the first time it is invoked.
|
|
crate Memoized(query: &impl QueryContext, (): ()) -> usize {
|
|
query.increment()
|
|
}
|
|
}
|
|
|
|
salsa::query_definition! {
|
|
/// Because this query is transparent, each time it is invoked,
|
|
/// we will increment the counter.
|
|
#[storage(transparent)]
|
|
crate Transparent(query: &impl QueryContext, (): ()) -> usize {
|
|
query.increment()
|
|
}
|
|
}
|