speedtest-tui 0.1.1

A terminal-based network speed test tool with real-time gauges and graphs
pub mod cloudflare;
pub mod custom;
pub mod librespeed;

use async_trait::async_trait;

#[async_trait]
pub trait Provider: Send + Sync {
    #[allow(dead_code)]
    fn name(&self) -> &str;

    fn get_download_url(&self) -> String;
    fn get_upload_url(&self) -> String;
    fn get_ping_url(&self) -> String;

    #[allow(dead_code)]
    async fn get_servers(&self) -> anyhow::Result<Vec<ServerInfo>> {
        Ok(vec![])
    }

    #[allow(dead_code)]
    async fn select_best_server(&self) -> anyhow::Result<Option<ServerInfo>> {
        Ok(None)
    }
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ServerInfo {
    pub id: String,
    pub name: String,
    pub location: String,
    pub country: String,
    pub host: String,
    pub latency_ms: Option<f64>,
}

/// Get a provider by name
pub fn get_provider(name: &str) -> anyhow::Result<Box<dyn Provider>> {
    match name.to_lowercase().as_str() {
        "cloudflare" => Ok(Box::new(cloudflare::CloudflareProvider::new())),
        "librespeed" => Ok(Box::new(librespeed::LibrespeedProvider::new())),
        _ => anyhow::bail!("Unknown provider: {}", name),
    }
}