basic/
basic.rs

1use ip_allocator_client::Client;
2
3#[tokio::main]
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Create a new client
6    let client = Client::new("http://localhost:8000");
7
8    // Borrow an item from the freelist
9    println!("šŸ”„ Borrowing an item...");
10    // Pass None for immediate return, or Some(seconds) to wait for availability
11    // Example: client.handlers_ip_borrow(Some(30)).await? // Wait up to 30 seconds
12    let borrow_result = client.handlers_ip_borrow(None).await?;
13    println!("āœ… Borrowed item: {:?}", borrow_result.item);
14    println!("šŸŽŸļø  Borrow token: {}", borrow_result.borrow_token);
15
16    // Return the borrowed item to the freelist
17    println!("\nšŸ”„ Returning the item...");
18    let return_input = ip_allocator_client::types::ReturnInput {
19        item: borrow_result.item.clone(),
20        borrow_token: borrow_result.borrow_token.clone(),
21    };
22    let return_result = client.handlers_ip_return_item(&return_input).await?;
23    println!("āœ… Return operation initiated: {:?}", return_result);
24
25    // Check operation status
26    println!("\nšŸ”„ Checking operation status...");
27    let status = client
28        .handlers_ip_get_operation_status(&return_result.operation_id)
29        .await?;
30    println!("āœ… Operation status: {:?}", status);
31
32    Ok(())
33}