Struct tyche::dice::Rolled

source ·
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<'_>

source

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());
source

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.

source

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<'a> Clone for Rolled<'a>

source§

fn clone(&self) -> Rolled<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Rolled<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Describe for Rolled<'_>

source§

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 Display for Rolled<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

The output is equivalent to calling Self::describe(None).

source§

impl<'a> PartialEq for Rolled<'a>

source§

fn eq(&self, other: &Rolled<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for Rolled<'a>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a [MaybeRef].
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> MaybeSync for T

§

impl<'p, T> OrderedSeq<'p, T> for T
where T: Clone,