MinaCalc Rust Bindings
Safe and idiomatic Rust bindings for the MinaCalc C++ library, providing rhythm game difficulty calculation capabilities.
Overview
MinaCalc is a sophisticated difficulty calculator for rhythm games like Stepmania, and similar games. This Rust crate provides a safe, memory-managed interface to the original C++ library, allowing you to calculate:
- MSD (Mina Skill Difficulty) scores for all music rates (0.7x to 2.0x)
- SSR (Single Song Rating) scores for specific rates and score goals
- Multiple skillset evaluations (Stream, Jumpstream, Handstream, Stamina, etc.)
Features
- ✅ Memory Safety: RAII-based resource management prevents memory leaks
- ✅ Error Handling: Comprehensive error handling with descriptive messages
- ✅ Cross-Platform: Supports Windows (MSVC), Linux (GCC/Clang), and macOS
- ✅ C++17 Compatibility: Full support for modern C++ features
- ✅ Zero-Cost Abstractions: Minimal runtime overhead
- ✅ Comprehensive Testing: Unit tests and integration tests included
Installation
Prerequisites
- Rust: 1.70+ (install via rustup)
- C++ Compiler:
- Windows: MSVC (Visual Studio 2019+)
- Linux: GCC 7+ or Clang 6+
Quick Start
# Add to your Cargo.toml
# Or clone and build from source
API Reference
Core Types
Calc
Main calculator instance with automatic resource management.
Note
Represents a single note row in the rhythm game.
SkillsetScores
Difficulty scores for different gameplay skills.
MsdForAllRates
MSD scores for all supported music rates.
Error Handling
All functions return Result with descriptive error messages:
| Error Message | Description |
|---|---|
"Failed to create calculator" |
C++ library initialization failed |
"No notes provided" |
Empty note array provided |
"Music rate must be positive" |
Invalid music rate (≤ 0) |
"Score goal must be between 0 and 100" |
Invalid score goal |
Project Structure
minacalc-rs/
├── Cargo.toml # Rust project configuration
├── build.rs # C++ compilation and bindgen setup
├── API.h # C++ header file
├── API.cpp # C++ implementation
├── NoteDataStructures.h # C++ data structures
├── MinaCalc/ # Original MinaCalc C++ library
├── src/
│ ├── lib.rs # Library entry point
│ ├── bindings.rs # Auto-generated FFI bindings
│ └── wrapper.rs # Idiomatic Rust interface
├── examples/
│ ├── basic_usage.rs # Basic usage example
│ └── osu.rs # osu! integration example
├── assets/
│ └── test.osu # Test beatmap file
└── README.md # This file
Building from Source
Development Setup
# Clone repository
# Install dependencies
# Run tests
# Run examples
Cross-Platform Compilation
The build system automatically detects your platform and uses appropriate compiler flags:
- Windows (MSVC): Uses
/std:c++17 - Linux/macOS (GCC/Clang): Uses
-std=c++17
Troubleshooting
Common Issues
- MSVC not found: Install Visual Studio 2019+ with C++ workload
- Bindgen errors: Ensure you have
libclanginstalled - C++17 not supported: Update your compiler to a C++17-compatible version
Platform-Specific Notes
- Windows: Requires Visual Studio Build Tools or full Visual Studio
- Linux: May need
libclang-devpackage:sudo apt install libclang-dev - macOS: Requires Xcode Command Line Tools:
xcode-select --install
Testing
# Run all tests
# Run tests with output
# Run specific test
Examples
See the examples/ directory for complete working examples:
basic_usage.rs: Simple MSD/SSR calculationosu.rs: Integration with osu! beatmap parsing
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Acknowledgments
- Original MinaCalc library developers
- Rust FFI and bindgen communities
- Rhythm game community for feedback and testing
Changelog
v0.1.1
- Fixed MSVC compilation issues
- Improved cross-platform compatibility
- Added comprehensive error handling
- Translated documentation to English
v0.1.0
- Initial release
- Basic MSD/SSR calculation support
- Memory-safe Rust interface
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: docs.rs