Skip to main content

Crate reinhardt_grpc

Crate reinhardt_grpc 

Source
Expand description

gRPC support for Reinhardt framework

This crate provides gRPC infrastructure features for the Reinhardt framework.

§Features

  • Common Protobuf types (Empty, Timestamp, Error, PageInfo, BatchResult)
  • GraphQL over gRPC types (GraphQLRequest, GraphQLResponse, SubscriptionEvent)
  • gRPC error handling with production-safe error sanitization
  • gRPC service adapter trait
  • Server configuration with message size limits, request timeouts, and connection limits
  • Protobuf message nesting depth limits
  • Protobuf field constraint validation
  • Dependency injection support (with di feature)

§Security

This crate includes several security features:

  • Depth-limited decoding: Prevents stack overflow from deeply nested protobuf messages via depth_limit::DepthLimitedDecoder.
  • Field validation: Enforces protobuf field constraints (required fields, value ranges) via validation::ProtoValidator.
  • Error sanitization: Prevents information leakage through error messages via error::ErrorSanitizer.
  • DI error sanitization: Prevents type name leakage through DI error messages (with di feature).

§Usage

Users can define their own .proto files in their projects, and utilize the common types and adapter traits from this crate.

§Dependency Injection

Enable the di feature to use dependency injection in gRPC handlers:

[dependencies]
reinhardt-grpc = { version = "0.1", features = ["di"] }

Then use the #[grpc_handler] macro:

#[grpc_handler]
async fn get_user_impl(
    &self,
    request: Request<GetUserRequest>,
    #[inject] db: DatabaseConnection,
) -> Result<Response<User>, Status> {
    // db is automatically resolved
}

Re-exports§

pub use adapter::GrpcServiceAdapter;
pub use adapter::GrpcSubscriptionAdapter;
pub use depth_limit::DepthLimitError;
pub use depth_limit::DepthLimitedDecoder;
pub use error::ErrorSanitizer;
pub use error::GrpcError;
pub use error::GrpcResult;
pub use server::GrpcServerConfig;Deprecated
pub use server::GrpcServerConfigBuilder;
pub use server::MessageSizeLimiter;
pub use settings::GrpcServerSettings;
pub use settings::create_grpc_server_config_from_settings;
pub use validation::FieldRule;
pub use validation::ProtoValidator;
pub use validation::ValidationError;
pub use validation::ValidationRuleSet;

Modules§

adapter
gRPC service adapter
depth_limit
Protobuf message nesting depth limits
error
gRPC error types with safe error response handling
proto
Generated Protobuf code (common types provided by the framework).
server
gRPC server configuration
settings
Settings fragment for the gRPC server configuration.
validation
Protobuf message constraint validation