mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-02 09:46:06 +00:00
remove database_storage macro-rules macro
This commit is contained in:
parent
b8311f2a28
commit
5f9309f108
2 changed files with 25 additions and 151 deletions
|
@ -126,6 +126,31 @@ pub fn query_group(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
query_group::query_group(args, input)
|
||||
}
|
||||
|
||||
/// 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:
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// salsa::database_storage! {
|
||||
/// struct MyDatabaseStorage for MyDatabase {
|
||||
/// impl MyQueryGroup {
|
||||
/// fn my_query1() for MyQuery1;
|
||||
/// fn my_query2() for MyQuery2;
|
||||
/// }
|
||||
/// // ... other query groups go here ...
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// 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][hw] for more details.
|
||||
///
|
||||
/// [`salsa::Runtime`]: struct.Runtime.html
|
||||
/// [hw]: https://github.com/salsa-rs/salsa/tree/master/examples/hello_world
|
||||
#[proc_macro]
|
||||
pub fn database_storage(input: TokenStream) -> TokenStream {
|
||||
database_storage::database_storage(input)
|
||||
|
|
151
src/lib.rs
151
src/lib.rs
|
@ -474,157 +474,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// 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:
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// salsa::database_storage! {
|
||||
/// struct MyDatabaseStorage for MyDatabase {
|
||||
/// impl MyQueryGroup {
|
||||
/// fn my_query1() for MyQuery1;
|
||||
/// fn my_query2() for MyQuery2;
|
||||
/// }
|
||||
/// // ... other query groups go here ...
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// 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][hw] for more details.
|
||||
///
|
||||
/// [`salsa::Runtime`]: struct.Runtime.html
|
||||
/// [hw]: https://github.com/salsa-rs/salsa/tree/master/examples/hello_world
|
||||
#[macro_export]
|
||||
macro_rules! database_storage_old {
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
$v:vis struct $Storage:ident for $Database:ty {
|
||||
$(
|
||||
impl $TraitName:path {
|
||||
$(
|
||||
fn $query_method:ident() for $QueryType:path;
|
||||
)*
|
||||
}
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
#[derive(Default)]
|
||||
$(#[$attr])*
|
||||
$v struct $Storage {
|
||||
$(
|
||||
$(
|
||||
$query_method: <$QueryType as $crate::Query<$Database>>::Storage,
|
||||
)*
|
||||
)*
|
||||
}
|
||||
|
||||
/// Identifies a query and its key.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[doc(hidden)]
|
||||
$v struct __SalsaQueryDescriptor {
|
||||
kind: __SalsaQueryDescriptorKind
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
enum __SalsaQueryDescriptorKind {
|
||||
$(
|
||||
$(
|
||||
$query_method(<$QueryType as $crate::Query<$Database>>::Key),
|
||||
)*
|
||||
)*
|
||||
}
|
||||
|
||||
impl $crate::plumbing::DatabaseStorageTypes for $Database {
|
||||
type QueryDescriptor = __SalsaQueryDescriptor;
|
||||
type DatabaseStorage = $Storage;
|
||||
}
|
||||
|
||||
impl $crate::plumbing::DatabaseOps for $Database {
|
||||
fn for_each_query(
|
||||
&self,
|
||||
mut op: impl FnMut(&dyn $crate::plumbing::QueryStorageMassOps<Self>),
|
||||
) {
|
||||
$(
|
||||
$(
|
||||
op(&$crate::Database::salsa_runtime(self)
|
||||
.storage()
|
||||
.$query_method);
|
||||
)*
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl $crate::plumbing::QueryDescriptor<$Database> for __SalsaQueryDescriptor {
|
||||
fn maybe_changed_since(
|
||||
&self,
|
||||
db: &$Database,
|
||||
revision: $crate::plumbing::Revision,
|
||||
) -> bool {
|
||||
match &self.kind {
|
||||
$(
|
||||
$(
|
||||
__SalsaQueryDescriptorKind::$query_method(key) => {
|
||||
let runtime = $crate::Database::salsa_runtime(db);
|
||||
let storage = &runtime.storage().$query_method;
|
||||
<_ as $crate::plumbing::QueryStorageOps<$Database, $QueryType>>::maybe_changed_since(
|
||||
storage,
|
||||
db,
|
||||
revision,
|
||||
key,
|
||||
self,
|
||||
)
|
||||
}
|
||||
)*
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(
|
||||
$(
|
||||
impl $crate::plumbing::GetQueryTable<$QueryType> for $Database {
|
||||
fn get_query_table(
|
||||
db: &Self,
|
||||
) -> $crate::QueryTable<'_, Self, $QueryType> {
|
||||
$crate::QueryTable::new(
|
||||
db,
|
||||
&$crate::Database::salsa_runtime(db)
|
||||
.storage()
|
||||
.$query_method,
|
||||
)
|
||||
}
|
||||
|
||||
fn get_query_table_mut(
|
||||
db: &mut Self,
|
||||
) -> $crate::QueryTableMut<'_, Self, $QueryType> {
|
||||
let db = &*db;
|
||||
$crate::QueryTableMut::new(
|
||||
db,
|
||||
&$crate::Database::salsa_runtime(db)
|
||||
.storage()
|
||||
.$query_method,
|
||||
)
|
||||
}
|
||||
|
||||
fn descriptor(
|
||||
db: &Self,
|
||||
key: <$QueryType as $crate::Query<Self>>::Key,
|
||||
) -> <Self as $crate::plumbing::DatabaseStorageTypes>::QueryDescriptor {
|
||||
__SalsaQueryDescriptor {
|
||||
kind: __SalsaQueryDescriptorKind::$query_method(key),
|
||||
}
|
||||
}
|
||||
}
|
||||
)*
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
// Re-export the procedural macros.
|
||||
#[allow(unused_imports)]
|
||||
#[macro_use]
|
||||
|
|
Loading…
Reference in a new issue