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 modeblocking: Enable blocking/sync mode (mutually exclusive withasync)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 TLSnative-tls: Use native TLS implementationtracing: Enable tracing/logging support
Re-exports§
Modules§
Structs§
- Client
- The main client for interacting with the
TopStatsAPI. - Client
Builder - Builder for creating a
Client. - Client
Config - Configuration options for the
TopStatsclient.
Constants§
- DEFAULT_
BASE_ URL - The default base URL for the
TopStatsAPI. - USER_
AGENT - The User-Agent string sent with requests.
- VERSION
- The SDK version.