rosu_replay/
lib.rs

1//! # rosu-replay
2//!
3//! A Rust library for parsing and writing osu! replay files (.osr format).
4//!
5//! This library is a faithful port of the Python [`osrparse`](https://github.com/kszlim/osu-replay-parser) library,
6//! providing the same functionality for parsing and manipulating osu! replay files in Rust.
7//!
8//! ## Features
9//!
10//! - **Parse .osr replay files** - Read replay files from disk or memory
11//! - **Extract replay data and metadata** - Access all replay information including:
12//!   - Player information (username, score, combo, etc.)
13//!   - Game metadata (mode, mods, timestamp, etc.)
14//!   - Hit statistics (300s, 100s, 50s, misses, etc.)
15//!   - Replay events (cursor movement, key presses)
16//!   - Life bar data over time
17//! - **Write replay files** - Save modified replays back to .osr format
18//! - **Support all game modes** - osu!standard, osu!taiko, osu!catch, osu!mania
19//! - **API compatibility** - Parse replay data from osu! API v1 responses
20//!
21//! ## Quick Start
22//!
23//! Add this to your `Cargo.toml`:
24//!
25//! ```toml
26//! [dependencies]
27//! rosu-replay = "0.1"
28//! ```
29//!
30//! ## Basic Usage
31//!
32//! ```rust,no_run
33//! use rosu_replay::Replay;
34//!
35//! // Parse a replay file
36//! let replay = Replay::from_path("path/to/replay.osr")?;
37//!
38//! println!("Player: {}", replay.username);
39//! println!("Score: {}", replay.score);
40//! println!("Max Combo: {}", replay.max_combo);
41//! println!("Game Mode: {:?}", replay.mode);
42//!
43//! // Access replay events
44//! for event in &replay.replay_data {
45//!     match event {
46//!         rosu_replay::ReplayEvent::Osu(osu_event) => {
47//!             println!("Cursor at ({}, {}) at time +{}ms",
48//!                 osu_event.x, osu_event.y, osu_event.time_delta);
49//!         }
50//!         _ => {} // Handle other game modes
51//!     }
52//! }
53//!
54//! // Write the replay back
55//! replay.write_path("output.osr")?;
56//! # Ok::<(), Box<dyn std::error::Error>>(())
57//! ```
58//!
59//! ## Working with API Data
60//!
61//! ```rust,no_run
62//! use rosu_replay::{parse_replay_data, GameMode};
63//!
64//! // Parse replay data from osu! API v1
65//! let api_data = b"base64_encoded_replay_data";
66//! let events = parse_replay_data(api_data, false, false, GameMode::Std)?;
67//! # Ok::<(), Box<dyn std::error::Error>>(())
68//! ```
69//!
70//! ## Attribution
71//!
72//! This library is a port of the Python [`osrparse`](https://github.com/kszlim/osu-replay-parser) library
73//! by kszlim and contributors. The original Python implementation provided the foundation for understanding
74//! the .osr file format and replay data structures.
75//!
76//! ## Examples
77//!
78//! See the `examples/` directory for more comprehensive usage examples.
79
80pub mod error;
81pub mod packer;
82pub mod replay;
83pub mod types;
84pub mod unpacker;
85
86#[cfg(feature = "wasm")]
87pub mod wasm;
88
89pub use error::ReplayError;
90pub use packer::Packer;
91pub use replay::Replay;
92pub use types::*;
93
94/// Parse replay data from a string (for API usage)
95pub fn parse_replay_data(
96    data_string: &[u8],
97    decoded: bool,
98    decompressed: bool,
99    mode: GameMode,
100) -> Result<Vec<ReplayEvent>, ReplayError> {
101    replay::parse_replay_data(data_string, decoded, decompressed, mode)
102}