mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 05:07:27 +00:00
31 lines
705 B
Rust
31 lines
705 B
Rust
use crate::queries;
|
|
use std::cell::Cell;
|
|
|
|
#[derive(Default)]
|
|
pub struct DatabaseImpl {
|
|
runtime: salsa::runtime::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::Runtime<DatabaseImpl> {
|
|
&self.runtime
|
|
}
|
|
}
|