diff --git a/src/database.rs b/src/database.rs index 801e2cd..5a32bd9 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,6 +1,9 @@ -use std::any::Any; +use std::{any::Any, borrow::Cow}; -use crate::{zalsa::ZalsaDatabase, Durability, Event, Revision}; +use crate::{ + zalsa::{IngredientIndex, ZalsaDatabase}, + Durability, Event, Revision, +}; /// The trait implemented by all Salsa databases. /// You can create your own subtraits of this trait using the `#[salsa::db]`(`crate::db`) procedural macro. @@ -38,6 +41,19 @@ pub trait Database: Send + AsDynDatabase + Any + ZalsaDatabase { zalsa_local.report_untracked_read(db.zalsa().current_revision()) } + /// Return the "debug name" (i.e., the struct name, etc) for an "ingredient", + /// which are the fine-grained components we use to track data. This is intended + /// for debugging and the contents of the returned string are not semver-guaranteed. + /// + /// Ingredient indices can be extracted from [`DependencyIndex`](`crate::DependencyIndex`) values. + fn ingredient_debug_name(&self, ingredient_index: IngredientIndex) -> Cow<'_, str> { + Cow::Borrowed( + self.zalsa() + .lookup_ingredient(ingredient_index) + .debug_name(), + ) + } + /// Execute `op` with the database in thread-local storage for debug print-outs. fn attach(&self, op: impl FnOnce(&Self) -> R) -> R where diff --git a/src/lib.rs b/src/lib.rs index d1b22e7..f701fc1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,6 +44,7 @@ pub use self::revision::Revision; pub use self::runtime::Runtime; pub use self::storage::Storage; pub use self::update::Update; +pub use self::zalsa::IngredientIndex; pub use crate::attach::with_attached_database; pub use salsa_macros::accumulator; pub use salsa_macros::db;