Skip to main content

grpc_client

Attribute Macro grpc_client 

Source
#[grpc_client]
Expand description

Generate a gRPC client that wraps a tonic-generated service client

This macro generates a client struct that implements an API trait by delegating to a tonic gRPC client, converting between domain types and protobuf messages.

§Example

#[modkit::grpc_client(
    api = "crate::contracts::UsersApi",
    tonic = "modkit_users_v1::users_service_client::UsersServiceClient<tonic::transport::Channel>",
    package = "modkit.users.v1"
)]
pub struct UsersGrpcClient;

This generates:

  • A struct wrapping the tonic client
  • An async connect(uri) method
  • A from_channel(Channel) constructor
  • Validation that the client implements the API trait

Note: The actual trait implementation must be provided manually, as procedural macros cannot introspect trait methods from external modules at compile time. Each method should convert requests/responses using .into().