macro_rules! database_storage {
(
$(#[$attr:meta])*
$v:vis struct $Storage:ident for $Database:ty {
$(
impl $TraitName:path {
$(
fn $query_method:ident() for $QueryType:path;
)*
}
)*
}
) => { ... };
(
$(#[$attr:meta])*
$v:vis struct $Storage:ident<$($lt:lifetime),*> for $Database:ty {
$(
impl $TraitName:path {
$(
fn $query_method:ident() for $QueryType:path;
)*
}
)*
}
) => { ... };
(
@STRUCT_IMPL
$(#[$attr:meta])*
$v:vis struct $Storage:ident [$($lts:tt)*] for $Database:ty {
$(
impl $TraitName:path {
$(
fn $query_method:ident() for $QueryType:path;
)*
}
)*
}
) => { ... };
(
@TRAIT_IMPL [$($lts:tt)*] $Database:ty;
impl $TraitName:path {
$(
fn $query_method:ident() for $QueryType:path;
)*
}
$(
impl $TailTraitName:path {
$(
fn $tail_query_method:ident() for $TailQueryType:path;
)*
}
)*
) => { ... };
(
@TRAIT_IMPL [$($lts:tt)*] $Database:ty;
) => { ... };
(
@QUERY_IMPL [$($lts:tt)*] $Database:ty;
fn $query_method:ident() for $QueryType:path;
$(
fn $tail_query_method:ident() for $TailQueryType:path;
)*
) => { ... };
(
@QUERY_IMPL [$($lts:tt)*] $Database:ty;
) => { ... };
}
This macro generates the "query storage" that goes into your database.
It requires you to list all of the query groups that you need as well
as the queries within those groups. The format looks like so:
salsa::database_storage! {
struct MyDatabaseStorage for MyDatabase {
impl MyQueryGroup {
fn my_query1() for MyQuery1;
fn my_query2() for MyQuery2;
}
}
}
Here, MyDatabase
should be the name of your database type. The
macro will then generate a struct named MyDatabaseStorage
that
is used by the salsa::Runtime
. MyQueryGroup
should be the
name of your query group.
See the hello_world
example for more details.