salsa/examples/storage_varieties/queries.rs

28 lines
750 B
Rust
Raw Normal View History

2018-09-29 08:50:08 +00:00
crate trait CounterContext: salsa::BaseQueryContext {
fn increment(&self) -> usize;
}
crate trait QueryContext: CounterContext {
salsa::query_prototype! {
fn memoized() for Memoized;
fn transparent() for Transparent;
}
}
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-09-29 08:50:08 +00:00
crate Memoized(query: &impl QueryContext, (): ()) -> usize {
query.increment()
}
}
salsa::query_definition! {
2018-09-29 08:53:59 +00:00
/// Because this query is transparent, each time it is invoked,
/// we will increment the counter.
2018-09-29 08:50:08 +00:00
#[storage(transparent)]
crate Transparent(query: &impl QueryContext, (): ()) -> usize {
query.increment()
}
}