#[db]Expand description
Defines a Salsa database struct or database trait.
A database is the state container passed to Salsa operations. Its storage holds inputs, tracked and interned values, and memoized query results.
This macro accepts no options. Its effect depends on the annotated item:
- On a struct, it implements Salsa’s storage plumbing. The struct must have named fields and
one of them must be named
storage, conventionally with typesalsa::Storage<Self>. - On a trait, it adds the hidden methods Salsa uses to view a database as that trait. Database
traits conventionally extend
salsa::Database. - On a trait implementation, it implements those hidden view methods. Every implementation of
a trait annotated with
#[salsa::db]must also carry#[salsa::db].
§Example
ⓘ
#[salsa::db]
#[derive(Clone, Default)]
struct MyDatabase {
storage: salsa::Storage<Self>,
}
#[salsa::db]
trait MyDatabaseView: salsa::Database {}
#[salsa::db]
impl MyDatabaseView for MyDatabase {}
#[salsa::db]
impl salsa::Database for MyDatabase {}