mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-13 00:40:22 +00:00
f14d846146
cc #17
31 lines
687 B
Rust
31 lines
687 B
Rust
use crate::queries;
|
|
use std::cell::Cell;
|
|
|
|
#[derive(Default)]
|
|
pub struct DatabaseImpl {
|
|
runtime: salsa::Runtime<DatabaseImpl>,
|
|
counter: Cell<usize>,
|
|
}
|
|
|
|
salsa::database_storage! {
|
|
pub struct DatabaseImplStorage for DatabaseImpl {
|
|
impl queries::Database {
|
|
fn memoized() for queries::Memoized;
|
|
fn volatile() for queries::Volatile;
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|