batch_list/
batch_list.rs

1//! Batch list example
2//!
3//! This example demonstrates how to list batch operations using a stream.
4//!
5//! To run this example, you need to have a Gemini API key.
6//!
7//! ```sh
8//! export GEMINI_API_KEY=your_api_key
9//! cargo run --package gemini-rust --example batch_list
10//! ```
11
12use futures::stream::StreamExt;
13use gemini_rust::Gemini;
14
15#[tokio::main]
16async fn main() -> Result<(), Box<dyn std::error::Error>> {
17    // Get the API key from the environment
18    let api_key = std::env::var("GEMINI_API_KEY").expect("GEMINI_API_KEY not set");
19
20    // Create a new Gemini client
21    let gemini = Gemini::new(api_key);
22
23    println!("Listing all batch operations...");
24
25    // List all batch operations using the stream
26    let stream = gemini.list_batches(5); // page_size of 5
27    tokio::pin!(stream);
28
29    while let Some(result) = stream.next().await {
30        match result {
31            Ok(operation) => {
32                println!(
33                    "  - Batch: {}, State: {:?}, Created: {}",
34                    operation.name, operation.metadata.state, operation.metadata.create_time
35                );
36            }
37            Err(e) => {
38                eprintln!("Error fetching batch operation: {}", e);
39            }
40        }
41    }
42
43    println!("\nFinished listing operations.");
44
45    Ok(())
46}