cryptologo 0.1.2

Rust client for crypto-logo.com — 413 cryptocurrency logos in SVG, PNG, WebP, ICO
Documentation
use serde::{Deserialize, Serialize};
use std::fmt;

/// A cryptocurrency coin with logo availability metadata.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Coin {
    /// Display name (e.g., "Bitcoin")
    pub name: String,
    /// Trading symbol (e.g., "BTC")
    pub ticker: String,
    /// URL-safe identifier (e.g., "bitcoin-btc")
    pub slug: String,
    /// Whether a PNG logo is available
    pub has_png: bool,
    /// Whether an SVG logo is available
    pub has_svg: bool,
    /// Localized names for search
    pub search_terms: Vec<String>,
    /// CoinGecko market cap ranking
    pub market_cap_rank: Option<i32>,
}

/// Supported image formats for logo serving.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogoFormat {
    Svg,
    Png,
    WebP,
    Jpeg,
    Ico,
}

impl fmt::Display for LogoFormat {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            LogoFormat::Svg => write!(f, "svg"),
            LogoFormat::Png => write!(f, "png"),
            LogoFormat::WebP => write!(f, "webp"),
            LogoFormat::Jpeg => write!(f, "jpeg"),
            LogoFormat::Ico => write!(f, "ico"),
        }
    }
}

/// Options for logo requests.
#[derive(Debug, Clone, Default)]
pub struct LogoOptions {
    /// Output width in pixels
    pub width: Option<u32>,
    /// Output height in pixels (defaults to width)
    pub height: Option<u32>,
    /// Background hex color without # (e.g., "FFFFFF")
    pub bg: Option<String>,
}

/// Errors from the CryptoLogo client.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// HTTP request failed
    #[error("HTTP error: {0}")]
    Http(#[from] reqwest::Error),

    /// Resource not found (404)
    #[error("Not found: {0}")]
    NotFound(String),

    /// Server returned an error status
    #[error("HTTP {status}: {url}")]
    Status { status: u16, url: String },

    /// I/O error
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),
}