permit provider fns to be variadic as well

This commit is contained in:
Niko Matsakis 2018-10-18 21:15:17 -04:00
parent ed2cf2333f
commit c0d8a08de9
2 changed files with 32 additions and 5 deletions

View file

@ -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<DB> $crate::plumbing::QueryFunction<DB> for $QueryType
where DB: $DbTrait
{
fn execute(db: &DB, key: <Self as $crate::Query<DB>>::Key)
fn execute(db: &DB, $key_name: <Self as $crate::Query<DB>>::Key)
-> <Self as $crate::Query<DB>>::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<DB> $crate::plumbing::QueryFunction<DB> for $QueryType
where DB: $DbTrait
{
fn execute(db: &DB, ($($key_name),*): <Self as $crate::Query<DB>>::Key)
-> <Self as $crate::Query<DB>>::Value
{
$fn_path(db, $($key_name),*)
}
}
};

View file

@ -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
}