Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 1.06 KB

db.md

File metadata and controls

32 lines (21 loc) · 1.06 KB

Defining the database struct

First, we need to create the database struct. Typically it is only used by the "driver" of your application; the one which starts up the program, supplies the inputs, and relays the outputs.

In calc, the database struct is in the db module, and it looks like this:

{{#include ../../../examples/calc/db.rs:db_struct}}

The #[salsa::db] attribute marks the struct as a database. It must have a field named storage whose type is salsa::Storage<Self>, but it can also contain whatever other fields you want.

Implementing the salsa::Database trait

In addition to the struct itself, we must add an impl of salsa::Database:

{{#include ../../../examples/calc/db.rs:db_impl}}

Implementing the salsa::ParallelDatabase trait

If you want to permit accessing your database from multiple threads at once, then you also need to implement the ParallelDatabase trait:

{{#include ../../../examples/calc/db.rs:par_db_impl}}