diff --git a/src/lib.rs b/src/lib.rs index ccdc94c9..7f5cecae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -228,6 +228,7 @@ macro_rules! query_group { fn_path($($fn_path)*); db_trait($query_trait); query_type($QueryType); + key($($key_name: $key_ty),*); ] } )* @@ -277,6 +278,8 @@ macro_rules! query_group { } }; + // Handle fns of one argument: once parenthesized patterns are stable on beta, + // we can remove this special case. ( @query_fn[ storage($($storage:ident)*); @@ -284,15 +287,39 @@ macro_rules! query_group { fn_path($fn_path:path); db_trait($DbTrait:path); query_type($QueryType:ty); + key($key_name:ident: $key_ty:ty); ] ) => { impl $crate::plumbing::QueryFunction for $QueryType where DB: $DbTrait { - fn execute(db: &DB, key: >::Key) + fn execute(db: &DB, $key_name: >::Key) -> >::Value { - $fn_path(db, key) + $fn_path(db, $key_name) + } + } + }; + + // Handle fns of N arguments: once parenthesized patterns are stable on beta, + // we can use this code for all cases. + ( + @query_fn[ + storage($($storage:ident)*); + method_name($method_name:ident); + fn_path($fn_path:path); + db_trait($DbTrait:path); + query_type($QueryType:ty); + key($($key_name:ident: $key_ty:ty),*); + ] + ) => { + impl $crate::plumbing::QueryFunction for $QueryType + where DB: $DbTrait + { + fn execute(db: &DB, ($($key_name),*): >::Key) + -> >::Value + { + $fn_path(db, $($key_name),*) } } }; diff --git a/tests/variadic.rs b/tests/variadic.rs index ec246b7f..760f76af 100644 --- a/tests/variadic.rs +++ b/tests/variadic.rs @@ -18,7 +18,7 @@ salsa::query_group! { } } -fn none(_db: &impl HelloWorldDatabase, (): ()) -> u32 { +fn none(_db: &impl HelloWorldDatabase) -> u32 { 22 } @@ -26,11 +26,11 @@ fn one(_db: &impl HelloWorldDatabase, k: u32) -> u32 { k * 2 } -fn two(_db: &impl HelloWorldDatabase, (a, b): (u32, u32)) -> u32 { +fn two(_db: &impl HelloWorldDatabase, a: u32, b: u32) -> u32 { a * b } -fn trailing(_db: &impl HelloWorldDatabase, (a, b): (u32, u32)) -> u32 { +fn trailing(_db: &impl HelloWorldDatabase, a: u32, b: u32) -> u32 { a - b }