[−][src]Function mice::roll_dice
pub fn roll_dice(input: &str) -> Result<i64, RollError>
Evaluate a dice expression! This function takes the usual dice expression format, and allows an arbitrary number of terms.
let dice_expression = "d20 + 5 - d2"; println!("{}", roll_dice(dice_expression)?);
Providing input that will overflow an i64
will produce unexpected behavior,
though it should never panic.
An Err
is returned in the following cases:
- A d0 is used
- The sum of all terms is too high
- The sum of all terms is too low
- Nonsense input
If a number >= 9223372036854775808 (2^63) is given, it is replaced, prior to evaluation, with 1. This is considered a bug, and will change in a future release.