rainforestt-contract 0.5.2

Generated Rust gRPC types for rainforestt contract proto
Documentation
  • Coverage
  • 33.33%
    2 out of 6 items documented0 out of 2 items with examples
  • Size
  • Source code size: 22.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 138.9 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 28s Average build duration of successful builds.
  • all releases: 28s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • shufangyii

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、负载均衡等)