mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-08-08 12:58:43 +00:00

Some checks failed
Test / Test (push) Has been cancelled
Book / Book (push) Has been cancelled
Release-plz / Release-plz release (push) Has been cancelled
Release-plz / Release-plz PR (push) Has been cancelled
Test / Miri (push) Has been cancelled
Test / Shuttle (push) Has been cancelled
Test / Benchmarks (push) Has been cancelled
Book / Deploy (push) Has been cancelled
* outline all tracing events * outline log events
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
use tracing::Level;
|
|
|
|
use crate::storage::HasStorage;
|
|
use crate::{Database, Storage};
|
|
|
|
/// Default database implementation that you can use if you don't
|
|
/// require any custom user data.
|
|
#[derive(Clone)]
|
|
pub struct DatabaseImpl {
|
|
storage: Storage<Self>,
|
|
}
|
|
|
|
impl Default for DatabaseImpl {
|
|
fn default() -> Self {
|
|
Self {
|
|
// Default behavior: tracing debug log the event.
|
|
storage: Storage::new(if tracing::enabled!(Level::DEBUG) {
|
|
Some(Box::new(|event| {
|
|
crate::tracing::debug!("salsa_event({:?})", event)
|
|
}))
|
|
} else {
|
|
None
|
|
}),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl DatabaseImpl {
|
|
/// Create a new database; equivalent to `Self::default`.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
pub fn storage(&self) -> &Storage<Self> {
|
|
&self.storage
|
|
}
|
|
}
|
|
|
|
impl Database for DatabaseImpl {}
|
|
|
|
// SAFETY: The `storage` and `storage_mut` fields return a reference to the same storage field owned by `self`.
|
|
unsafe impl HasStorage for DatabaseImpl {
|
|
#[inline(always)]
|
|
fn storage(&self) -> &Storage<Self> {
|
|
&self.storage
|
|
}
|
|
|
|
#[inline(always)]
|
|
fn storage_mut(&mut self) -> &mut Storage<Self> {
|
|
&mut self.storage
|
|
}
|
|
}
|