Struct tyche::dice::DieRoll

source ·
#[non_exhaustive]
pub struct DieRoll { pub val: u8, pub added_by: Option<Modifier>, pub dropped_by: Option<Modifier>, pub changes: Vec<ValChange>, }
Expand description

Single die produced from rolling Dice and optionally applying Modifiers

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§val: u8

Value that was rolled

§added_by: Option<Modifier>

Modifier that caused the addition of this die, if any

§dropped_by: Option<Modifier>

Modifier that caused the drop of this die, if any

§changes: Vec<ValChange>

Modifications that were made to the value of the roll

Implementations§

source§

impl DieRoll

source

pub fn add(&mut self, from: Modifier)

Marks this die roll as added by a given modifier, setting Self::added_by.

§Panics

Panics if Self::added_by is already Some.

source

pub fn drop(&mut self, from: Modifier)

Marks this die roll as dropped by a given modifier, setting Self::dropped_by.

§Panics

Panics if Self::dropped_by is already Some.

source

pub fn change(&mut self, from: Modifier, new_val: u8)

Replaces the die roll’s value and logs the change made.

source

pub const fn is_original(&self) -> bool

Indicates whether this die roll was part of the original set (not added by a modifier).

source

pub const fn is_additional(&self) -> bool

Indicates whether this die roll was added as the result of a modifier being applied. This is the direct inverse of DieRoll::is_original().

source

pub const fn is_dropped(&self) -> bool

Indicates whether this die roll has been dropped by a modifier.

source

pub const fn is_kept(&self) -> bool

Indicates whether this die roll is being kept (has not been dropped by a modifier). This is the direct inverse of DieRoll::is_dropped().

source

pub fn is_changed(&self) -> bool

Indicates whether this die roll’s value has been directly changed by a modifier.

source

pub const fn new(val: u8) -> Self

Creates a new die roll with the given value.

Trait Implementations§

source§

impl Clone for DieRoll

source§

fn clone(&self) -> DieRoll

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 Debug for DieRoll

source§

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

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

impl Display for DieRoll

source§

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

Formats the value using the given formatter. Read more

The format of a die roll is simply the plain numeric value of the roll. If the roll was dropped, it is appended with (d).

§Examples
use tyche::dice::DieRoll;

let roll = DieRoll::new(4);
assert_eq!(roll.to_string(), "4");
use tyche::dice::{DieRoll, Modifier};

let mut roll = DieRoll::new(16);
let kh_mod = Modifier::KeepHigh(1);
roll.drop(kh_mod);
assert_eq!(roll.to_string(), "16 (d)");
source§

impl Ord for DieRoll

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for DieRoll

source§

fn eq(&self, other: &DieRoll) -> 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 PartialOrd for DieRoll

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for DieRoll

source§

impl StructuralPartialEq for DieRoll

Auto Trait Implementations§

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,