| Crates.io | osrs-highscores |
| lib.rs | osrs-highscores |
| version | 0.2.0 |
| created_at | 2024-12-21 18:45:45.733276+00 |
| updated_at | 2024-12-23 07:26:29.038027+00 |
| description | A simple Rust library to retrieve Old School RuneScape (OSRS) Highscores for various game modes. |
| homepage | |
| repository | https://github.com/matnich89/osrs-highscores-search-rust |
| max_upload_size | |
| id | 1491334 |
| size | 10,219 |
A simple Rust library to retrieve Old School RuneScape (OSRS) Highscores for various game modes. This library leverages the official OSRS endpoints and uses ureq for making HTTP requests.
Player, Stat)Add the following to your Cargo.toml:
[dependencies]
osrs-highscores = "0.2.0"
serde = { version = "1.0", features = ["derive"] }
(If you are copying the code directly, ensure you also include ureq in your Cargo.toml. This library depends on ureq.)
[dependencies]
ureq = "2.12.1"
serde = { version = "1.0", features = ["derive"] }
Then run:
cargo build
use osrs_highscores::{
standard_high_scores,
ironman_high_scores,
hardcode_high_scores,
ultimate_high_scores
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let standard_player = standard_high_scores("Zezima")?;
println!("{:#?}", standard_player);
// Serialize to JSON
let json = serde_json::to_string(&standard_player)?;
println!("JSON: {}", json);
// Pretty print JSON
let pretty_json = serde_json::to_string_pretty(&standard_player)?;
println!("Pretty JSON:\n{}", pretty_json);
Ok(())
}
Below are the primary functions you can call:
| Function | Description |
|---|---|
standard_high_scores(player) |
Fetch the Standard OSRS Highscores for the given player. |
ironman_high_scores(player) |
Fetch the Ironman OSRS Highscores for the given player. |
hardcode_high_scores(player) |
Fetch the Hardcore Ironman OSRS Highscores for player. |
ultimate_high_scores(player) |
Fetch the Ultimate Ironman OSRS Highscores for player. |
Each function returns a Result<Player, Box<dyn std::error::Error>>, where a successful result will contain a Player struct.
The raw response from the official Old School RuneScape Highscores is essentially a CSV-like text with lines such as:
53479,1280,6406598
47916,65,452980
64661,53,136985
...
-1,-1
-1,-1
...
Each line typically contains rank,level,xp for a specific skill or minigame. Some lines might include "-1" values to indicate missing or irrelevant stats. Manually parsing this can be confusing since you need to know which line corresponds to which skill or activity. This library abstracts away that complexity by:
Player object.use osrs_highscores::standard_high_scores;
use serde_json;
fn main() {
match standard_high_scores("Zezima") {
Ok(player) => {
println!("Found player: {:?}", player.name);
for stat in player.stats {
println!("{} => Level: {}, XP: {}", stat.skill, stat.level, stat.xp);
}
// Serialize to JSON
if let Ok(json) = serde_json::to_string_pretty(&player) {
println!("Player data as JSON:\n{}", json);
}
},
Err(e) => {
eprintln!("Error fetching player data: {}", e);
}
}
}
PlayerRepresents a single player's highscores. Contains:
#[derive(Debug, Serialize, Deserialize)]
pub struct Player {
pub name: String,
pub stats: Vec<Stat>,
}
Stat entries for the player's skillsStatRepresents a single skill's rank, level, and experience.
#[derive(Debug, Serialize, Deserialize)]
pub struct Stat {
pub skill: String,
pub rank: i64,
pub level: i64,
pub xp: i64,
}
Attack, Mining, Cooking)"Player not found" is returned.ureq::Error or a Box<dyn std::error::Error>.This project is licensed under the MIT License.
See the LICENSE file for details.