salsa/tests/storage_varieties/implementation.rs
Niko Matsakis 238be96432 introduce group storage structs to use from database_storage macro
This also detected a bunch of crate visibility mismatches in the
tests.
2019-01-23 05:35:07 -05:00

31 lines
711 B
Rust

use crate::queries;
use std::cell::Cell;
#[derive(Default)]
pub(crate) struct DatabaseImpl {
runtime: salsa::Runtime<DatabaseImpl>,
counter: Cell<usize>,
}
salsa::database_storage! {
pub(crate) struct DatabaseImplStorage for DatabaseImpl {
impl queries::Database {
fn memoized() for queries::MemoizedQuery;
fn volatile() for queries::VolatileQuery;
}
}
}
impl queries::Counter for DatabaseImpl {
fn increment(&self) -> usize {
let v = self.counter.get();
self.counter.set(v + 1);
v
}
}
impl salsa::Database for DatabaseImpl {
fn salsa_runtime(&self) -> &salsa::Runtime<DatabaseImpl> {
&self.runtime
}
}