macro_rules! api_specification {
(
pool_item: $pool_item:ty,
api_name: $api:ident,
add_request: $add_request:ty,
calls: [
$(
{
call_name: $call:ident,
request: $request:ty,
response: $response:ty
}
),* $(,)?
],
generics: $t:ident: $generics:ident
) => { ... };
(
pool_item: $pool_item:ty,
api_name: $api:ident,
add_request: $add_request:ty,
calls: [
$(
{
call_name: $call:ident,
request: $request:ty,
response: $response:ty
}
),* $(,)?
]
) => { ... };
}Expand description
Generates an API enum and trait implementations for a pool item.
§⚠️ Legacy Macro
This is the legacy approach. For new code, prefer the pool_item
attribute macro, which provides the same functionality with less boilerplate.
§Migration Example
Before (with api_specification!):
ⓘ
api_specification!(
pool_item: MyItem,
api_name: MyItemApi,
add_request: MyItemAddRequest,
calls: [
{ call_name: DoWork, request: DoWorkRequest, response: DoWorkResponse },
]
);After (with #[pool_item]):
ⓘ
#[pool_item]
impl MyItem {
pub fn new(id: u64) -> Self { /* ... */ }
#[messaging(DoWorkRequest, DoWorkResponse)]
pub fn do_work(&self) { /* ... */ }
}§Parameters
pool_item: The type of the pool item.api_name: The name of the generated API enum.add_request: The type for the add request.calls: A list of call definitions where each call consists of:call_name: The name of the call.request: The type of the request for the call.response: The type of the response for the call.
generics(optional): The name of a generic type and its bound. Only required for the generic case.
§Example
ⓘ
// Non-generic case
api_specification!(
pool_item: Randoms,
api_name: RandomsApi,
add_request: RandomsAddRequest,
calls: [
{ call_name: Mean, request: MeanRequest, response: MeanResponse },
{ call_name: Sum, request: SumRequest, response: SumResponse },
{ call_name: Panic, request: PanicRequest, response: PanicResponse },
]
);
// Generic case
api_specification!(
pool_item: RandomsBatch<T>,
api_name: RandomsBatchApi,
add_request: RandomsBatchAddRequest<T>,
calls: [
{ call_name: SumOfSums, request: SumOfSumsRequest, response: SumOfSumsResponse },
],
generics: T: InnerThreadPool
);This will generate an enum RandomsApi with variants Mean, Sum, and Panic for the non-generic case,
and RandomsBatchApi with the SumOfSums variant for the generic case, along with various generics implementations
and conversion functions for the provided request and response types.