Expand description
Rollpoly
- A comprehensive dice rolling library for tabletop gaming
This library provides functionality to parse and evaluate dice notation strings and return the results as arrays of numbers.
§Features
- Basic dice rolling: Roll any number of dice with any number of sides (e.g.,
4d10
,d20
) - Arithmetic operations: Add, subtract, multiply, and divide dice results (e.g.,
3d6 + 5
) - Advanced mechanics: Keep/drop highest/lowest, exploding dice, rerolling, success counting
- Safety limits: Maximum of 10 dice per roll to prevent excessive resource usage
- Error handling: Comprehensive error reporting for invalid input
- Random number generation: Uses cryptographically secure random number generation
§Quick Start
use rollpoly::roll;
// Roll 4 ten-sided dice and add 17
let results = roll("4d10 + 17").unwrap();
println!("Rolled: {:?}", results);
// Handle errors gracefully
match roll("invalid input") {
Ok(results) => println!("Results: {:?}", results),
Err(error) => println!("Error: {}", error),
}
§Supported Syntax
The library supports the following dice notation syntax:
4d10
: Roll a 10-sided die 4 timesd20
: Roll a 20-sided die once (implicit count)2d6 + 3
: Roll 2d6 and add 33d8 - 2
: Roll 3d8 and subtract 21d4 * 3
: Roll 1d4 and multiply by 35d6 / 2
: Roll 5d6 and divide by 24d8 // 3
: Roll 4d8 and floor divide by 3
§Safety Limits
To prevent excessive resource usage and potential abuse, the library enforces
a maximum limit of 10 dice per roll. Attempts to roll more than 10 dice will
result in a DiceError::TooManyDice
error.
§Error Handling
All functions return Result
types with descriptive error messages.
The DiceError
type provides both the original input and a description
of what went wrong.
Enums§
- Dice
Error - Error type for dice rolling operations
Functions§
- roll
- Rolls dice based on the provided dice notation string.