dice_command_parser/dice_roll_with_op.rs
1use crate::dice_roll::{DiceRoll, Operation};
2
3#[derive(Clone, Debug, PartialEq)]
4/// A struct that contains the dice roll, plus whether the roll is negative or positive.
5pub struct DiceRollWithOp {
6 /// The `DiceRoll`
7 pub dice_roll: DiceRoll,
8 /// How the roll should be applied. Either it should have a positive impact on the total sum, or a negative one
9 pub operation: Operation,
10}
11
12/// A convinience method for creating a `DiceRollWithOp`.
13///
14/// # Examples
15///
16/// This represents a d6 with no modifier
17/// ```
18/// use dice_command_parser::{dice_roll::{DiceRoll, Operation}, dice_roll_with_op::DiceRollWithOp};
19///
20/// let dice_roll = DiceRollWithOp::new(DiceRoll::new_regular_roll(6, None, 1), Operation::Addition);
21/// ```
22impl DiceRollWithOp {
23 #[must_use]
24 /// Creates a new `DiceRollWithOp`
25 pub fn new(dice_roll: DiceRoll, operation: Operation) -> Self {
26 DiceRollWithOp {
27 dice_roll,
28 operation: operation,
29 }
30 }
31}