| Crates.io | aoc_leaderboard |
| lib.rs | aoc_leaderboard |
| version | 2.0.0 |
| created_at | 2024-12-28 07:28:17.454053+00 |
| updated_at | 2025-11-28 06:34:10.016759+00 |
| description | Strongly-typed wrapper for Advent of Code leaderboard data |
| homepage | https://github.com/clechasseur/aoc_leaderbot/tree/main/aoc_leaderboard#readme |
| repository | https://github.com/clechasseur/aoc_leaderbot |
| max_upload_size | |
| id | 1496906 |
| size | 110,219 |
Strongly-typed wrapper for an Advent of Code leaderboard and a convenient way to fetch its data.
Add aoc_leaderboard to your dependencies:
[dependencies]
# Enable http feature to be able to fetch leaderboard data
aoc_leaderboard = { version = "2.0.0", features = ["http"] }
or by running:
cargo add aoc_leaderboard --features http
use std::env;
use aoc_leaderboard::aoc::{Leaderboard, LeaderboardCredentials};
use dotenvy::dotenv;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Maybe your config lives in a `.env` file?
let _ = dotenv();
// Fetch leaderboard ID and AoC credentials from the environment.
let leaderboard_id = env::var("AOC_LEADERBOARD_ID")?.parse()?;
let credentials = aoc_credentials()?;
// Load the leaderboard from the AoC website.
// Careful not to call this more than once every **15 minutes**.
let year = 2024;
let leaderboard = Leaderboard::get(year, leaderboard_id, &credentials).await?;
// Do something useful.
println!("Leaderboard for year {year} has {} members.", leaderboard.members.len());
Ok(())
}
fn aoc_credentials() -> anyhow::Result<LeaderboardCredentials> {
Ok(env::var("AOC_VIEW_KEY")
.map(LeaderboardCredentials::ViewKey)
.or_else(|_| env::var("AOC_SESSION").map(LeaderboardCredentials::SessionCookie))?)
}
The above example is available here. For complete API usage, see the docs.
aoc_leaderboard currently builds on Rust 1.88 or newer.
For information about contributing to this project, see CONTRIBUTING. For information regarding local development, see DEVELOPMENT.