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);
14
15    // Return an item to the freelist
16    println!("\nšŸ”„ Returning an item...");
17    let return_input = ip_allocator_client::types::ReturnInput {
18        item: serde_json::json!({"ip": "192.168.1.100"}),
19    };
20    let return_result = client.handlers_ip_return_item(&return_input).await?;
21    println!("āœ… Return operation initiated: {:?}", return_result);
22
23    // Check operation status
24    println!("\nšŸ”„ Checking operation status...");
25    let status = client
26        .handlers_ip_get_operation_status(&return_result.operation_id)
27        .await?;
28    println!("āœ… Operation status: {:?}", status);
29
30    Ok(())
31}