pypinindia 0.1.0

Rust library for Indian pincode lookup and geographical information
Documentation
use pypinindia::PincodeData;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load data from CSV file
    // You need to provide the path to your pincode CSV data
    let data_file = std::env::var("PYPININDIA_DATA_FILE")
        .unwrap_or_else(|_| "All_India_pincode_data.csv".to_string());

    println!("Loading pincode data from: {}", data_file);
    let data = PincodeData::new(Some(&data_file))?;

    // Get statistics
    let stats = data.get_statistics();
    println!("\n=== Dataset Statistics ===");
    println!("Total records: {}", stats.total_records);
    println!("Unique pincodes: {}", stats.unique_pincodes);
    println!("Unique states: {}", stats.unique_states);
    println!("Unique districts: {}", stats.unique_districts);

    // Lookup a specific pincode
    println!("\n=== Pincode Lookup: 110001 ===");
    match data.get_pincode_info("110001") {
        Ok(info) => {
            for office in info {
                println!("Office: {}", office.officename);
                println!("Type: {}", office.officetype);
                println!("State: {}", office.statename);
                println!("District: {}", office.districtname);
                println!("---");
            }
        }
        Err(e) => println!("Error: {}", e),
    }

    // Quick lookups
    println!("\n=== Quick Lookups ===");
    if let Ok(state) = data.get_state("110001") {
        println!("State: {}", state);
    }
    if let Ok(district) = data.get_district("110001") {
        println!("District: {}", district);
    }

    // Search by state
    println!("\n=== Search by State: Delhi ===");
    let delhi_pincodes = data.search_by_state("Delhi");
    println!("Found {} pincodes in Delhi", delhi_pincodes.len());
    println!(
        "First 5: {:?}",
        &delhi_pincodes[..5.min(delhi_pincodes.len())]
    );

    // Get all states
    println!("\n=== All States ===");
    let states = data.get_states();
    println!("Total states: {}", states.len());
    println!("First 5: {:?}", &states[..5.min(states.len())]);

    Ok(())
}