rpc_adapter

Crates.iorpc_adapter
lib.rsrpc_adapter
version0.1.12
created_at2025-10-23 03:08:32.274752+00
updated_at2025-10-24 10:26:02.16729+00
descriptionEnglish: RPC adapter for unified request handling / 中文: 统一请求处理的RPC适配器
homepagehttps://github.com/i18n-site/rust/tree/dev/rpc_adapter
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1896537
size92,566
i18n.site (i18nsite)

documentation

README

rpc_adapter

English | 中文

Table of Contents

Introduction

rpc_adapter is a Rust library that provides unified interfaces for handling requests from different RPC frameworks. It defines common traits for request objects, allowing code to work with various RPC implementations through a consistent API.

Usage

The library provides Req and Map traits that can be implemented by RPC request types. Implementations are provided for volo-grpc and volo-http request types when the respective features are enabled.

Example:

use rpc_adapter::Req;

fn handle_request<T: Req>(req: T) {
    let headers = req.headers();
    // Process headers and request data
}

Design

The library defines two core traits:

  • Map: Interface for accessing key-value data (e.g., headers)
  • Req: Interface for accessing request data including headers and extensions

Implementations of these traits are provided for different RPC frameworks through conditional compilation features.

Tech Stack

  • Rust 2024 edition
  • http crate for HTTP types
  • volo-grpc and volo-http for RPC implementations (optional features)

Directory Structure

src/
├── lib.rs          # Core traits and types
├── impl_volo_grpc.rs # volo-grpc implementation
├── impl_volo_http.rs # volo-http implementation

History

The concept of adapter patterns in RPC systems can be traced back to early distributed computing systems. This library follows that tradition by providing a clean abstraction layer between business logic and RPC framework specifics.


目录

介绍

rpc_adapter 是一个Rust库,为处理来自不同RPC框架的请求提供统一接口。它定义了请求对象的通用特性,允许代码通过一致的API与各种RPC实现协作。

使用

该库提供了ReqMap特性,可由RPC请求类型实现。当启用相应功能时,为volo-grpcvolo-http请求类型提供实现。

示例:

use rpc_adapter::Req;

fn handle_request<T: Req>(req: T) {
    let headers = req.headers();
    // 处理头部和请求数据
}

设计

该库定义了两个核心特性:

  • Map:访问键值数据的接口(例如,头部)
  • Req:访问请求数据的接口,包括头部和扩展

通过条件编译功能为不同的RPC框架提供这些特性的实现。

技术栈

  • Rust 2024 版本
  • http crate 用于HTTP类型
  • volo-grpc 和 volo-http 用于RPC实现(可选功能)

目录结构

src/
├── lib.rs          # 核心特性和类型
├── impl_volo_grpc.rs # volo-grpc 实现
├── impl_volo_http.rs # volo-http 实现

历史

RPC系统中的适配器模式概念可以追溯到早期的分布式计算系统。该库遵循这一传统,通过在业务逻辑和RPC框架细节之间提供一个清晰的抽象层。

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 68

cargo fmt