# [−][src]Crate critfail

Evaluation and rolling of D&D 5e die roll expressions.

The `RollExpression`

trait provides methods for dealing with the
various kinds of rolls. `Roll`

provides the simplest text-in,
text-out interface for rolling expressions an printing the result
regardless of the type of roll.

use critfail::{RollExpression, Roll}; let check = Roll::new("r-3").unwrap(); let check_outcome = check.roll(); print!("{}", check_outcome); // eg. "11" print!("{:?}", check_outcome); // eg. "(14)-3" let damage = Roll::new("2d8+6").unwrap(); let damage_outcome = damage.roll(); print!("{}", damage_outcome); // eg. "13" print!("{:?}", damage_outcome); // eg. "[2+5]+6" let attack = Roll::new("r+1?2d6+4").unwrap(); let attack_outcome = attack.roll(); print!("{}", attack_outcome); // eg. "10 ? 16" print!("{:?}", attack_outcome); // eg. "(9)+1 ? [6+6]+4"

In order to handle the outcome of a `Roll`

programatically, roll
expressions are split into `Check`

rolls, `Damage`

rolls, and
`Attack`

rolls, each with their own outcome type which provides
methods for determining the score and makeup of the results for
each.

# Features

`wasm-bindgen`

: Enable this when compiling for wasm32 targets, or random number generation won't work.

## Structs

Attack | An attack roll consisting of a check and a damage roll. |

AttackOutcome | The outcome of an attack roll. |

AttackOutcomeBuilder | This is used to create a 'fudged' |

Check | An ability check - roll a d20, potentially with modifiers or advantage. |

CheckOutcome | The outcome of a check roll. |

CheckOutcomeBuilder | This is used to create a 'fudged' |

Damage | A list of dice to roll and modifiers to add, usually used for damage. |

DamageOutcome | The outcome of a check roll. |

DamageOutcomeBuilder | This is used to create a 'fudged' |

ParseError | Represents an error parsing a roll expression. |

## Enums

AdvState | The advantage state of an ability check. |

CritScore | The score of a roll that could be a critical hit/failure |

OutcomePart | Enum representing the different kinds of values that can be returned for damage or the modifier on a check. |

Roll | Any kind of roll—either a check, damage, or attack roll. |

RollOutcome | The outcome of rolling a check, damage, or attack roll. |

## Traits

RollExpression | Used for structs defining a set of dice that can be rolled. |

## Type Definitions

Score | The number type that is used when reporting the score of a roll |

Sides | The number type that is used for specifying the number of sides on a die |