#[non_exhaustive]pub struct DieRoll {
pub val: u8,
pub added_by: Option<Modifier>,
pub dropped_by: Option<Modifier>,
pub changes: Vec<ValChange>,
}
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
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
impl DieRoll
sourcepub fn add(&mut self, from: Modifier)
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
.
sourcepub fn drop(&mut self, from: Modifier)
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
.
sourcepub fn change(&mut self, from: Modifier, new_val: u8)
pub fn change(&mut self, from: Modifier, new_val: u8)
Replaces the die roll’s value and logs the change made.
sourcepub const fn is_original(&self) -> bool
pub const fn is_original(&self) -> bool
Indicates whether this die roll was part of the original set (not added by a modifier).
sourcepub const fn is_additional(&self) -> bool
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()
.
sourcepub const fn is_dropped(&self) -> bool
pub const fn is_dropped(&self) -> bool
Indicates whether this die roll has been dropped by a modifier.
sourcepub const fn is_kept(&self) -> bool
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()
.
sourcepub fn is_changed(&self) -> bool
pub fn is_changed(&self) -> bool
Indicates whether this die roll’s value has been directly changed by a modifier.
Trait Implementations§
source§impl Display for DieRoll
impl Display for DieRoll
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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
impl Ord for DieRoll
source§impl PartialEq for DieRoll
impl PartialEq for DieRoll
source§impl PartialOrd for DieRoll
impl PartialOrd for DieRoll
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for DieRoll
impl StructuralPartialEq for DieRoll
Auto Trait Implementations§
impl RefUnwindSafe for DieRoll
impl Send for DieRoll
impl Sync for DieRoll
impl Unpin for DieRoll
impl UnwindSafe for DieRoll
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
].