Skip to content

Commit

Permalink
Borrow Dice for Rolled::from_dice_and_rolls
Browse files Browse the repository at this point in the history
  • Loading branch information
Gawdl3y committed Apr 24, 2024
1 parent a2a4f21 commit 8d3816b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/dice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ impl Rolled<'_> {

/// Creates a new rolled set of dice from a given set of dice and an iterator of values.
#[must_use]
pub fn from_dice_and_rolls(dice: Dice, rolls: impl IntoIterator<Item = u8>) -> Rolled<'static> {
pub fn from_dice_and_rolls(dice: &Dice, rolls: impl IntoIterator<Item = u8>) -> Rolled {
Rolled {
rolls: rolls.into_iter().map(DieRoll::new).collect(),
dice: Cow::Owned(dice),
dice: Cow::Borrowed(dice),
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/dice/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Modifier {
/// // Upon being applied, the modifier will drop the 1 roll, roll a new 1 from the predetermined RNG, drop that too,
/// // then roll a new 4 from the RNG.
/// // Final expected rolled dice set, after rr1 modifier: 4d6rr1[3, 6, 1 (d), 2, 1 (d), 4]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[2].drop(rr1_mod);
/// expected.rolls[4].add(rr1_mod);
/// expected.rolls[4].drop(rr1_mod);
Expand Down Expand Up @@ -71,7 +71,7 @@ pub enum Modifier {
///
/// // Upon being applied, the modifier will drop the 1 roll and roll a new 1 from the predetermined RNG.
/// // Final expected rolled dice set, after r1 modifier: 4d6r1[3, 6, 1 (d), 2, 1]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[2].drop(r1_mod);
/// expected.rolls[4].add(r1_mod);
/// assert_eq!(rolled, expected);
Expand Down Expand Up @@ -114,7 +114,7 @@ pub enum Modifier {
/// // Upon being applied, the modifier will see that a 6 (the max die value) was rolled, roll a new additional 6, see
/// // that is also the max die value, then roll a new 4 as well.
/// // Final expected rolled dice set, after x modifier: 4d6x[3, 6, 1, 2, 6, 4]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[4].add(x_mod);
/// expected.rolls[5].add(x_mod);
/// assert_eq!(rolled, expected);
Expand Down Expand Up @@ -145,7 +145,7 @@ pub enum Modifier {
///
/// // Upon being applied, the modifier will see that a 6 (the max die value) was rolled and roll a new additional 6.
/// // Final expected rolled dice set, after xo modifier: 4d6xo[3, 6, 1, 2, 6]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[4].add(xo_mod);
/// assert_eq!(rolled, expected);
/// # Ok::<(), dicey::dice::Error>(())
Expand Down Expand Up @@ -183,7 +183,7 @@ pub enum Modifier {
///
/// // Upon being applied, the modifier will drop all rolls except the highest one, so 3, 1, and 2 will be dropped.
/// // Final expected rolled dice set, after kh modifier: 4d6kh[3 (d), 6, 1 (d), 2 (d)]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[0].drop(kh_mod);
/// expected.rolls[2].drop(kh_mod);
/// expected.rolls[3].drop(kh_mod);
Expand Down Expand Up @@ -211,7 +211,7 @@ pub enum Modifier {
///
/// // Upon being applied, the modifier will drop all rolls except the two highest, so 1 and 2 will be dropped.
/// // Final expected rolled dice set, after kh2 modifier: 4d6kh2[3, 6, 1 (d), 2 (d)]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[2].drop(kh2_mod);
/// expected.rolls[3].drop(kh2_mod);
/// assert_eq!(rolled, expected);
Expand Down Expand Up @@ -243,7 +243,7 @@ pub enum Modifier {
///
/// // Upon being applied, the modifier will drop all rolls except the lowest one, so 3, 6, and 2 will be dropped.
/// // Final expected rolled dice set, after kl modifier: 4d6kl[3 (d), 6 (d), 1, 2 (d)]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[0].drop(kl_mod);
/// expected.rolls[1].drop(kl_mod);
/// expected.rolls[3].drop(kl_mod);
Expand Down Expand Up @@ -271,7 +271,7 @@ pub enum Modifier {
///
/// // Upon being applied, the modifier will drop all rolls except the two lowest, so 3 and 6 will be dropped.
/// // Final expected rolled dice set, after kl2 modifier: 4d6kl2[3 (d), 6 (d), 1, 2]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[0].drop(kl2_mod);
/// expected.rolls[1].drop(kl2_mod);
/// assert_eq!(rolled, expected);
Expand Down Expand Up @@ -302,7 +302,7 @@ pub enum Modifier {
/// // Upon being applied, the modifier will replace the values of all rolls less than 3 with 3, so 1 and 2 will
/// // both become 3.
/// // Final expected rolled dice set, after min3 modifier: 4d6min3[3, 6, 3 (m), 3 (m)]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[2].change(min3_mod, 3);
/// expected.rolls[3].change(min3_mod, 3);
/// assert_eq!(rolled, expected);
Expand Down Expand Up @@ -332,7 +332,7 @@ pub enum Modifier {
///
/// // Upon being applied, the modifier will replace the values of all rolls greater than 3 with 3, so 6 will become 3.
/// // Final expected rolled dice set, after max3 modifier: 4d6max3[3, 3 (m), 1, 2]
/// let mut expected = Rolled::from_dice_and_rolls(dice.clone(), premade_rolls);
/// let mut expected = Rolled::from_dice_and_rolls(&dice, premade_rolls);
/// expected.rolls[1].change(max3_mod, 3);
/// assert_eq!(rolled, expected);
/// # Ok::<(), dicey::dice::Error>(())
Expand Down

0 comments on commit 8d3816b

Please sign in to comment.