pub struct Rolled<'a> {
pub rolls: Vec<DieRoll>,
pub dice: Cow<'a, Dice>,
}
Expand description
Representation of the result from rolling Dice
Fields§
§rolls: Vec<DieRoll>
Each individual die roll that was made
dice: Cow<'a, Dice>
Dice that were rolled to produce this
Implementations§
source§impl Rolled<'_>
impl Rolled<'_>
sourcepub fn total(&self) -> Result<u16, Error>
pub fn total(&self) -> Result<u16, Error>
Calculates the total of all roll values.
§Errors
If there is an integer overflow while summing the die rolls, an error variant is returned.
§Examples
use tyche::dice::{roller::{FastRand as FastRandRoller, Roller}, Dice};
let dice = Dice::new(4, 8);
let rolled = FastRandRoller::default().roll(&dice, true)?;
let total = rolled.total()?;
assert_eq!(total, rolled.rolls.iter().map(|roll| roll.val as u16).sum());
sourcepub fn into_owned(self) -> Rolled<'static>
pub fn into_owned(self) -> Rolled<'static>
Moves all of self’s owned data into a new instance and clones any unowned data in order to create a 'static
instance of self.
sourcepub fn from_dice_and_rolls(
dice: &Dice,
rolls: impl IntoIterator<Item = u8>
) -> Rolled<'_>
pub fn from_dice_and_rolls( dice: &Dice, rolls: impl IntoIterator<Item = u8> ) -> Rolled<'_>
Creates a new rolled set of dice from a given set of dice and an iterator of values.
Trait Implementations§
source§impl Describe for Rolled<'_>
impl Describe for Rolled<'_>
source§fn describe(&self, list_limit: Option<usize>) -> String
fn describe(&self, list_limit: Option<usize>) -> String
Builds a string of the dice the roll is from and a list of all of the individual rolled dice
(see DieRoll::fmt()
).
If list_limit
is specified and there are more rolls than it, the list of rolled dice will be truncated and
appended with “X more…” (where X is the remaining roll count past the max).
§Examples
use std::borrow::Cow;
use tyche::{dice::{Dice, DieRoll, Rolled}, expr::Describe};
let dice = Dice::builder().count(4).sides(6).keep_high(2).build();
let kh_mod = dice.modifiers[0];
let rolled = Rolled {
rolls: vec![
DieRoll::new(6),
{
let mut roll = DieRoll::new(2);
roll.drop(kh_mod);
roll
},
DieRoll::new(5),
{
let mut roll = DieRoll::new(3);
roll.drop(kh_mod);
roll
},
],
dice: Cow::Borrowed(&dice),
};
assert_eq!(rolled.describe(None), "4d6kh2[6, 2 (d), 5, 3 (d)]");
assert_eq!(rolled.describe(Some(2)), "4d6kh2[6, 2 (d), 2 more...]");
source§impl<'a> PartialEq for Rolled<'a>
impl<'a> PartialEq for Rolled<'a>
impl<'a> Eq for Rolled<'a>
impl<'a> StructuralPartialEq for Rolled<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Rolled<'a>
impl<'a> Send for Rolled<'a>
impl<'a> Sync for Rolled<'a>
impl<'a> Unpin for Rolled<'a>
impl<'a> UnwindSafe for Rolled<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef
].