opencellid 0.2.0

Rust client library for the OpenCellID API — sync and async clients with tracing, structured errors, and bounded I/O.
Documentation
//! Async smoke test against the live OpenCellID API.
//!
//! Run with: `OPENCELLID_API_KEY=... cargo run --example get_cell -- 262 2 801 86355`

use std::env;

use opencellid::{CellKey, ClientBuilder, Radio};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::try_from_default_env()
                .unwrap_or_else(|_| "opencellid=debug,info".into()),
        )
        .init();

    let api_key = env::var("OPENCELLID_API_KEY")
        .map_err(|_| "set OPENCELLID_API_KEY to your OpenCellID token")?;

    let mut args = env::args().skip(1);
    let mcc: u16 = args.next().as_deref().unwrap_or("262").parse()?;
    let mnc: u16 = args.next().as_deref().unwrap_or("2").parse()?;
    let lac: u32 = args.next().as_deref().unwrap_or("801").parse()?;
    let cell_id: u64 = args.next().as_deref().unwrap_or("86355").parse()?;

    let client = ClientBuilder::new().api_key(api_key).build()?;
    let key = CellKey::new(mcc, mnc, lac, cell_id).with_radio(Radio::Lte);

    match client.get_cell(key).await {
        Ok(cell) => println!("cell: {cell:#?}"),
        Err(e) => eprintln!("lookup failed: {e}"),
    }
    Ok(())
}