Skip to main content

Crate topstats

Crate topstats 

Source
Expand description

§TopStats Rust SDK

A Rust SDK for interacting with the TopStats.gg API, which provides statistics for Discord bots listed on Top.gg.

§Features

  • Async-first design with optional blocking mode
  • Multiple HTTP backends: reqwest (async) or ureq (blocking)
  • Built-in rate limiting with automatic retry for short delays
  • Type-safe models with serde serialization
  • Tracing support for logging (optional)

§Quick Start (Async)

use topstats::Client;

#[tokio::main]
async fn main() -> Result<(), topstats::Error> {
    let client = Client::new("your-api-token")?;

    // Get bot information
    let bot = client.get_bot(432610292342587392).await?;
    println!("Bot: {} has {} monthly votes", bot.name, bot.monthly_votes);

    Ok(())
}

§Blocking Mode

For synchronous code, disable default features and enable blocking:

[dependencies]
topstats = { version = "0.1", default-features = false, features = ["blocking", "ureq-client"] }
use topstats::Client;

fn main() -> Result<(), topstats::Error> {
    let client = Client::new("your-api-token")?;
    let bot = client.get_bot(432610292342587392)?;
    println!("Bot: {}", bot.name);
    Ok(())
}

§Feature Flags

  • async (default): Enable async mode
  • blocking: Enable blocking/sync mode (mutually exclusive with async)
  • reqwest-client (default): Use reqwest as the HTTP backend (async)
  • ureq-client: Use ureq as the HTTP backend (blocking)
  • rustls-tls (default): Use rustls for TLS
  • native-tls: Use native TLS implementation
  • tracing: Enable tracing/logging support

Re-exports§

pub use error::Error;
pub use error::Result;
pub use models::*;

Modules§

error
Error types for the TopStats SDK.
models
Data models for the TopStats API.

Structs§

Client
The main client for interacting with the TopStats API.
ClientBuilder
Builder for creating a Client.
ClientConfig
Configuration options for the TopStats client.

Constants§

DEFAULT_BASE_URL
The default base URL for the TopStats API.
USER_AGENT
The User-Agent string sent with requests.
VERSION
The SDK version.