rainforestt-contract

Crates.iorainforestt-contract
lib.rsrainforestt-contract
version0.5.2
created_at2025-11-07 01:37:00.671304+00
updated_at2025-11-07 01:37:00.671304+00
descriptionGenerated Rust gRPC types for rainforestt contract proto
homepage
repository
max_upload_size
id1920964
size22,743
Mr.Tree (shufangyii)

documentation

README

rainforestt-contract

Crates.io

Rainforestt gRPC 服务的 Rust SDK。基于 tonic 构建。

安装

将以下依赖添加到你的 Cargo.toml

[dependencies]
rainforestt-contract = "1.0.0"  # 使用最新版本
tokio = { version = "1.0", features = ["full"] }

快速开始

use rainforestt_contract::ai::{self, ai_service_client::AiServiceClient};
use tonic::transport::Channel;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 连接到 gRPC 服务器
    let channel = Channel::from_static("http://[::1]:50051")
        .connect()
        .await?;

    // 创建客户端
    let mut client = AiServiceClient::new(channel);

    // 创建请求
    let request = tonic::Request::new(ai::YourRequest {
        // 设置请求参数
    });

    // 发送请求
    let response = client
        .your_rpc_method(request)
        .await?;

    println!("Response: {:?}", response);

    Ok(())
}

异步流示例

如果服务定义了流式 RPC,你可以这样使用:

use futures::StreamExt;

async fn stream_example() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = // ... 创建客户端

    let request = tonic::Request::new(ai::StreamRequest {
        // 设置请求参数
    });

    let mut stream = client
        .streaming_rpc(request)
        .await?
        .into_inner();

    while let Some(response) = stream.next().await {
        match response {
            Ok(msg) => println!("Got: {:?}", msg),
            Err(e) => eprintln!("Error: {:?}", e),
        }
    }

    Ok(())
}

特性

  • 完整的 Protocol Buffers 生成的类型定义
  • 异步客户端实现(基于 tokio)
  • 支持单向 RPC 和流式 RPC
  • tonic 的所有功能(TLS、负载均衡等)
Commit count: 0

cargo fmt