| Crates.io | rainforestt-contract |
| lib.rs | rainforestt-contract |
| version | 0.5.2 |
| created_at | 2025-11-07 01:37:00.671304+00 |
| updated_at | 2025-11-07 01:37:00.671304+00 |
| description | Generated Rust gRPC types for rainforestt contract proto |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1920964 |
| size | 22,743 |
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(())
}