Struct Roll

Source
pub struct Roll {
    pub drex: String,
    pub values: Vec<(DieRollTerm, Vec<i8>)>,
    pub total: i32,
}
Expand description

Represents the results of an evaluated die roll expression.

The Roll struct contains the original die roll expression passed to the roll_dice() function.

The list of values will always be a vector containing at least one element because roll expressions are not valid without at least 1 term. Each resulting value is a tuple containing the parsed DieRollTerm and a vector of values. For DieRollTerm::Modifier terms, this will be a single-element vector containing the modifier value. For DieRollTerm::DieRoll terms, this will be a vector containing the results of each die roll.

The total field contains the net result of evaluating the entire roll expression.

You can evaluate a roll expression (perform a roll) mutliple times by converting it into an iterator.

Fields§

§drex: String

A die roll expression conforming to the format specification

§values: Vec<(DieRollTerm, Vec<i8>)>

The results of evaluating each term in the expression

§total: i32

The net final result of evaluating all terms in the expression

Trait Implementations§

Source§

impl Debug for Roll

Source§

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

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

impl Display for Roll

Formats roll results, including die rolls, in a human-readable string.

For example, if the original expression was 3d6+5, formatting the Roll struct might result in the following text:

3d6[3,4,6]+5 (Total: 18)

Source§

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

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

impl IntoIterator for Roll

Converts an evaluated roll expression into an iterator, allowing the expression to be evaluated (including re-rolling of dice) multiple times.

Source§

type Item = Roll

The type of the elements being iterated over.
Source§

type IntoIter = RollIterator

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for Roll

§

impl RefUnwindSafe for Roll

§

impl Send for Roll

§

impl Sync for Roll

§

impl Unpin for Roll

§

impl UnwindSafe for Roll

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
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.

Source§

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

Source§

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>,

Source§

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>,

Source§

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.