mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 16:35:21 +00:00
2d2bdfe7f1
They aren't meant to be things to model oneself after.
38 lines
946 B
Rust
38 lines
946 B
Rust
use crate::counter::Counter;
|
|
use crate::log::Log;
|
|
|
|
crate trait CounterContext: salsa::QueryContext {
|
|
fn clock(&self) -> &Counter;
|
|
fn log(&self) -> &Log;
|
|
}
|
|
|
|
crate trait QueryContext: CounterContext {
|
|
salsa::query_prototype! {
|
|
fn memoized2() for Memoized2;
|
|
fn memoized1() for Memoized1;
|
|
fn volatile() for Volatile;
|
|
}
|
|
}
|
|
|
|
salsa::query_definition! {
|
|
crate Memoized2(query: &impl QueryContext, (): ()) -> usize {
|
|
query.log().add("Memoized2 invoked");
|
|
query.memoized1().of(())
|
|
}
|
|
}
|
|
|
|
salsa::query_definition! {
|
|
crate Memoized1(query: &impl QueryContext, (): ()) -> usize {
|
|
query.log().add("Memoized1 invoked");
|
|
let v = query.volatile().of(());
|
|
v / 3
|
|
}
|
|
}
|
|
|
|
salsa::query_definition! {
|
|
#[storage(volatile)]
|
|
crate Volatile(query: &impl QueryContext, (): ()) -> usize {
|
|
query.log().add("Volatile invoked");
|
|
query.clock().increment()
|
|
}
|
|
}
|