Skip to main content

reinhardt_grpc_macros/
lib.rs

1//! Procedural macros for Reinhardt gRPC DI integration
2
3#![warn(missing_docs)]
4
5use proc_macro::TokenStream;
6use syn::parse_macro_input;
7
8mod crate_paths;
9mod grpc_handler;
10
11/// Attribute macro for gRPC handlers with dependency injection support
12///
13/// This macro enables the use of `#[inject]` parameters in gRPC service methods,
14/// allowing automatic dependency resolution from the `InjectionContext`.
15///
16/// # Parameters
17///
18/// Regular parameters are passed through as-is. Parameters marked with `#[inject]`
19/// are automatically resolved from the DI context.
20///
21/// # Requirements
22///
23/// 1. The function must have a `tonic::Request<T>` parameter
24/// 2. The request must have an `InjectionContext` in its extensions
25/// 3. All injected types must implement `Injectable`
26/// 4. The function must be `async`
27///
28/// # Error Handling
29///
30/// If dependency injection fails, the function returns `tonic::Status::internal`
31/// with an error message describing the failure.
32#[proc_macro_attribute]
33pub fn grpc_handler(_attr: TokenStream, item: TokenStream) -> TokenStream {
34	let input = parse_macro_input!(item as syn::ItemFn);
35
36	grpc_handler::expand_grpc_handler(input)
37		.unwrap_or_else(|err| err.to_compile_error())
38		.into()
39}